---
title: "Need function for convert image to byte and byte to image."  
description: "Need function for convert image to byte and byte to image."  
author: "Anonymous User"  
published: 2013-06-15  
updated: 2013-07-24  
canonical: https://www.mindstick.com/forum/1186/need-function-for-convert-image-to-byte-and-byte-to-image  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Need function for convert image to byte and byte to image.

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances),\
How to [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) to byte and byte to image in C#?\
Your help is a great appreciated.

## Replies

### Reply by Manmohan Jha

private byte[] ReadImg2Byte(Image fileName) { try { using (Bitmap image = new Bitmap(fileName)) { stream = new MemoryStream(); image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); } } catch (Exception ex) { MessageBox.Show(ex.Message); } return stream.ToArray(); }\
\
private Image view_img() { MemoryStream stream = new MemoryStream((byte[])byteimg); Bitmap image = new Bitmap(stream); return image; }\
Mj

### Reply by AVADHESH PATEL

Convert image to byte:\
public static byte[] _ImageToByte(Image img){ ImageConverter converter = new ImageConverter(); return (byte[])converter.ConvertTo(img, typeof(byte[]));}\
Convert Image to byte:\
public static Bitmap _ByteToImage(byte[] blob) { MemoryStream mStream = new MemoryStream(); byte[] pData = blob; mStream.Write(pData, 0, Convert.ToInt32(pData.Length)); Bitmap bm = new Bitmap(mStream, false); mStream.Dispose(); return bm; }


---

Original Source: https://www.mindstick.com/forum/1186/need-function-for-convert-image-to-byte-and-byte-to-image

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
