Link to home
Start Free TrialLog in
Avatar of cyman73
cyman73

asked on

Delphi, Fast loading of pixel data into TBitmap object from Array of Bytes

Hello all,

I have loaded the pixel data of my image into an array of Bytes.  I now need to load these pixels into a TBitmap object and I would like to do this the fastest way possible.  The array is height x width x 4 (bytes per pixel) and these images can be somewhat large (desktop sizes 1024x780 etc)RGBP.

I am using Delphi 7.

Thank you.

Avatar of imitchie
imitchie
Flag of New Zealand image

look at the free Graphics32 package. full source code included
1) Create an instance of Bitmap: TBitmap.

2) Set its width and height via Bitmap.Height and Bitmap.Width (byte array dimensions)

3) Use Bitmap.ScanLine[row] to write 4 bytes at a time (1 pixel).

If you provide more details regarding the structure of your array of bytes (e.g. in which order have the pixels have been copied, by scanline?), then I will be able to give you more help.
Avatar of cyman73
cyman73

ASKER

Do I have to copy every row?  I was hoping for some sort of an assignment statement.

I will take a look at the Graphics 32 package for now.
I am curious why you copied it to an array of bytes to begin with... Understanding that would help me to understand your situation and perhaps give you better adviice.  Copying to an array of bytes undoes some of the TBitmaps ability to handle varying color depths for you, etc.  If you would like me to look into it further, give me as much information as you can, please.
Avatar of cyman73

ASKER

Would anyone be able to provide me with a working example using SetDIBits and GetDIBits APIs?  Could these be the fastest way to do this task?

I am sorry for not being more specific.  I have been tasked with providing a function that gets an array of bytes (representing pixel data) that then gets loaded into a TBitmap object.  

Thank you
ASKER CERTIFIED SOLUTION
Avatar of den4b
den4b
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial