byte array to bitmap  
Author Message
sirithvasa





PostPosted: Visual C# General, byte array to bitmap Top

Hi there,

how can I create a bitmap within a byte array, using pinvoke I found functions like createBitmap, createBitmapIndirect in gdi32, but I don't know, how to use it, or are they the right functions. I have to use pinvoke!!!

Somebody can help me

Greets

sirithvasa



Visual C#1  
 
 
Mark Dawson





PostPosted: Visual C# General, byte array to bitmap Top

Hi,

> how can I create a bitmap within a byte array

Do you mean you want to create a bitmap object from a byte array If so you can do something like:

MemoryStream ms = new MemoryStream(byteArray);
Image img = Image.FromStream(ms);

Mark.r



 
 
sirithvasa





PostPosted: Visual C# General, byte array to bitmap Top

Hi Mark,

sorry for my english. I'm german and I didn't have speak and write english for a couble of years.

Is there no other way, to create a bitmap from a byte array I get the byte array commited from a other class and in this byte array are the raw bitmap data. The basic data like with, height etc aren't in this array. They have been calculated in further operations.

I have already read this form of bitmap creation in the MSDN Libary, but I think, thats not already what I want.

Greets

sirithvasa


 
 
Mark Dawson





PostPosted: Visual C# General, byte array to bitmap Top

Hi sirithvasa,

no worries about the english, I just wanted to clarify exactly what you were asking. If you want to create a bitmap from raw pixel data then you can use the LockBits method of the bitmap class to do that, see this post where I show a code example: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1126715&SiteID=1

Hope that helps, good luck.

Mark.



 
 
sirithvasa





PostPosted: Visual C# General, byte array to bitmap Top

No thats not what I want to do.... I have to place this bitmap into a printable document like a pdf or sent the data directly to a printer, but this version saves the file to a disk, thats not want I have to do..

Sorry, I have forgotten to say, that I have to place this bitmap into a printjob or a document.


 
 
Mark Dawson





PostPosted: Visual C# General, byte array to bitmap Top

Hi,

you can still use the code to first get a Bitmap object then instead of saving it you can put it into the printjob or document. You should post a new question with a different title asking how to put a bitmap into a printjob or document, I am not sure how to do that.

Mark.