Software Archive
Read-only legacy content
17060 Discussions

read bitmap from file to array

reinerb
Beginner
1,471 Views
Dear all,
I need to read several bitmap (*.bmp) files into a 3-D array to work on the pixel values.
I found a solution using Quickwin & LOADIMAGE & GETPIXEL. However this is very time consuming, so reading 500 files takes very long.
I tried to use other options, e.g. using GETIMAGE which reads the screen image into a buffer. However, I wasn't able to interprete the buffer format, and I also found that the buffer format differs on Windows98 and Windows 2000.
Then I tried the subroutine "BitmapGet" which is part of the QUICKWIN samples. I was able to read data which was created using "BitmapPut", but not when the screen was created using LOADIMAGE.
Does anybody know a better solution for this task? If necessary, I can provide the test program I'm working with.
Best regards, Reiner
0 Kudos
4 Replies
Intel_C_Intel
Employee
1,471 Views
Reiner
I do not have any solution to your problem, but could I know the way you are using BitmapGet and BitmapPut to make the buffer? My e-mail is in_vision@cablerocket.com.
Thanks in advance
OPiedrahita
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,471 Views
I think you'd be better off using a little Windows API than coping with GetImage/BitmapGet. Maybe API wouldn't be even necessary -- you should be able to parse the .bmp file yourself without involving any GUI operations.

The .bmp file consists of BITMAPFILEHEADER structure followed by BITMAPINFOHEADER structure. Then comes an array of bitmap data. You can find detailed specification of the format on . There are few tricky issues involved:

First, contents of the bitmap data depend on color depth. The easiest one is 24-bit bitmap -- the contents is simply an array of {R,G,B} triplets. For other formats, carefully check the documentation.

Second, if you want to put the data in a matrix you have to be careful with upside-down order, column-major vs. row-major order and especially padding used to align rows to 4-byte boundary.

If you want more general solution, you could use the following APIs:

hBmp = LoadImage(...LR_LOADFROMFILE) to load the bitmap;

hMemDC = CreateCompatibleDC to create a DC (canvas) in memory to put bitmap to;

i = SelectObject(hMemDC, hBmp) to associate the bitmap with the DC
;
i = GetObject(hBmp, SIZEOF(cBmp), LOC(cBmp)) to get info about the bitmap (size, depth etc)
;
i = GetDIBits(...) to get an array of bitmap data


There's a Fortran sample for storing the bitmap here. I think it's worth a look. Sorry, I can't provide any sample code myself.

HTH

Jugoslav
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,471 Views
The missing link is www.wotsit.org.
0 Kudos
Intel_C_Intel
Employee
1,471 Views
I receive the information.
Thank you very much for the help.
OPiedrahita
0 Kudos
Reply