Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Administrators
Posted

Something like

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Leaders
Posted
I would recommend PlausiblyDamp's 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.
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...