Convert bitmap to byte...

lidds

Well-known member
Joined
Nov 9, 2004
Messages
210
I have managed to put together some code (with help from other coders) that will capture my desktop into a bitmap variable, however now I need to convert this into a byte variable so that I can then insert into my image field within SQL server db.

Is anyone able to help me, I have search the net and I seem to find loads of example where you are reading a image from a file, however I can find nothing to help me with this.

Thanks in advance

Simon
 
Something like
C#:
System.Drawing.Bitmap bmp = (Bitmap) System.Drawing.Image.FromFile("c:\\windows\\winnt256.bmp");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] data = ms.GetBuffer();

might also work.
 
I would recommend PlausiblyDamps method because it stores the entire image file into the array, including the pixel format and dimensions. The first example only extracts raw pixel data to the array, which is not enough to reproduce the image later.
 
Back
Top