Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2005

Tip: Looking for answers? Try searching our database.

How to call GDI CreateBitmap function using C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Flo - 13 Sep 2005 14:13 GMT
Hi,

I do have a Bitmap object  in a C# application,  i would like to create a
bitmap using the GDI function CreateBitmap which could return me a valid
HBITMAP (Dont want to use the GetHBitmap method which returns a 24bits bitmap
which will loose any Alpha informations like transparency).

The declaration for the function will probably look like this :

[DllImport("gdi32.dll")]
public static extern IntPtr CreateBitmap(int nWidth, int nHeight, uint
cPlanes, uint cBitsPerPel, short[] lpvBits);

But i have no clue how to provide the parameters CBitsPerPel and lpvBits,
and what they do correspond to in the .NET Bitmap object.

Any idea how i could call this function properly ?

Thx.
Bob Powell [MVP] - 13 Sep 2005 22:02 GMT
Parameters
 nWidth
 [in] Specifies the bitmap width, in pixels.
 nHeight
 [in] Specifies the bitmap height, in pixels.
 cPlanes
 [in] Specifies the number of color planes used by the device.
 cBitsPerPel
 [in] Specifies the number of bits required to identify the color of a
single pixel.
 lpvBits
 [in] Pointer to an array of color data used to set the colors in a
rectangle of pixels. Each scan line in the rectangle must be word aligned
(scan lines that are not word aligned must be padded with zeros). If this
parameter is NULL, the contents of the new bitmap is undefined.
You can set the cBitsPerPixel to 32 and leave the lpvBits as null.

Signature

Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

> Hi,
>
[quoted text clipped - 16 lines]
>
> Thx.
Flo - 14 Sep 2005 09:20 GMT
First thanks a lot for answering my question so quickly. But my question was
more about where are the data of the bitmap stored in the bitmap .NET object ?

For example,  i instanciated a .NET bitmap object and i would like to call
the API CreateBitmap function to make a copy of the bitmap i got. I know
where to find the informations concerning the 4 first parameters (width,
height, number of planes, number of bits), but i have no clue where the data
of the bitmap is stored in the .NET Bitmap object.

Maybe u can help me with a sample implementation on how to retrieve these
data and to call the CreateBitmap function in order to get the similar
bitmap?

Thanks a lot. Regards.

> Parameters
>   nWidth
[quoted text clipped - 12 lines]
> parameter is NULL, the contents of the new bitmap is undefined.
> You can set the cBitsPerPixel to 32 and leave the lpvBits as null.
Bob Powell [MVP] - 14 Sep 2005 20:13 GMT
To get access to the image data itself you need to use the LockBits method.

The article on my site explains LockBits in great detail.

Signature

Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

> First thanks a lot for answering my question so quickly. But my question
> was
[quoted text clipped - 30 lines]
>> parameter is NULL, the contents of the new bitmap is undefined.
>> You can set the cBitsPerPixel to 32 and leave the lpvBits as null.
Flo - 14 Sep 2005 21:55 GMT
Thanks very much for the article Bob, this was exactly what i was looking for.

> To get access to the image data itself you need to use the LockBits method.
>
> The article on my site explains LockBits in great detail.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.