Graphics contents to Bimap object

  • Thread starter Thread starter degoo
  • Start date Start date
D

degoo

I draw on the surface of a control (System.Drawing.Graphics), and I'd like
to transfer to a Bitmap object. I have a routine to save the contents of a
Bitmap object (a Image) to a file on the pocket.

How can do this??

Thanks!!!
 
Hi,

It may be easier just to draw to a Bitmap object instead of the control and
then draw the Bitmap to the control. That way you already have the Bitmap
that you need to save. Otherwise, I believe you would have to P/Invoke
CreateDIBSection to get the control image. If you need to do the latter
solution then reply as such and I will post some more info on how to do it.

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
 
I would be interested in knowing how to P/Invoke CreateDIBSection to obtain
the controls image.

--Terry
 
Hi Terry,

Since there has been a high demand for this, I have decided to make a sample
available even though the accompanying whitepaper is not yet published.
This sample demonstrates how to use CreateDIBSection to build a .bmp file
from a control. It is only written in C# because it uses an unsafe code
block to manipulate the pointers used by the native functions.

http://download.microsoft.com/downl...4-9d17-fd6767e66908/SaveBitmapSampleSetup.exe

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Geoff Schwab said:
Hi Terry,

Since there has been a high demand for this, I have decided to make a sample
available even though the accompanying whitepaper is not yet published.
This sample demonstrates how to use CreateDIBSection to build a .bmp file
from a control. It is only written in C# because it uses an unsafe code
block to manipulate the pointers used by the native functions.

http://download.microsoft.com/downl...4-9d17-fd6767e66908/SaveBitmapSampleSetup.exe

Amazing!!!!!!!! Works fine and quickly!

Thanks for your help
 
Chris,

It is good to know it was useful! One thing to keep in mind is that even
though it is relatively efficient, it is not optimized at all because I
wanted to keep the sample simple to read. Some simple low-level
optimizations might be to use while loops with pointer checks instead of for
loops and to cache any variables used in the loops instead of dereferencing
structures. This is very old-school stuff but it more than doubled the
speed of a rectangle filling routine I wrote around GAPI.

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi All,

One quick caveat to anyone using this sample... I just discovered that my
use of 16 bit bitmaps is slightly incorrect in this sample. If no
compression is specified and BITMAPINFOHEADER.biBitCount is 16 then the
format is supposed to be 565, where as if the bit count is 15 then the
format is 0555. At the time I wrote the sample I was unable to obtain this
information so I saved 16 bit bitmaps as 555. The weird thing is that the
files load and look correct in Paint. I will do some more testing and then
update the sample and the whitepaper, the latter of which is not yet
published anyway.

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top