hello expert
I'm new in C# is any body Suggest me how can i convert the image into byte array..and vise versa ..if any body have some code sample help me out i m develop a wpf application and enable to find stream reader.
thanks in advance shashank
hello expert
I'm new in C# is any body Suggest me how can i convert the image into byte array..and vise versa ..if any body have some code sample help me out i m develop a wpf application and enable to find stream reader.
thanks in advance shashank
Do you only want the pixels or the whole image (including headers) as an byte array?
For pixels: Use the CopyPixels method on Bitmap. Something like:
var bitmap = new BitmapImage(uri);
//Pixel array
byte[] pixels = new byte[width * height * 4]; //account for stride if necessary and whether the image is 32 bit, 16 bit etc.
bitmap.CopyPixels(..size, pixels, fullStride, 0);
try this:
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}