- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In what format is the bitmap presented to you? A bmp file? A bitmap handle? Something other?
Using Windows APIs, you can load bitmap from a .bmp into a memory DC and operate on it using:
Jugoslav
Using Windows APIs, you can load bitmap from a .bmp into a memory DC and operate on it using:
INTEGER:: hBitmap, hScreenDC, hMemoryDC hBitmap = LoadImage(...LR_LOADFROMFILE) hScreenDC = GetDC(NULL) !Get screen DC hMemoryDC = CreateCompatibleDC(hScreenDC) iret = ReleaseDC(hScreenDC) iret = SelectObject(hMemoryDC, hBitmap) rgbColor = GetPixel(hMemoryDC, iX, iY) iRed = iand(rgbColor, Z'FF') iGreen = iand(ishl(rgbColor,-8), Z'FF') iBlue = iand(ishl(rgbColor,-16), Z'FF')Note that GetPixel/SetPixel are in general slow -- if you need huge raster operations, another method (operating on a DIB section) would be more suitable.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks alot! Yes, I am trying to load a bitmap from a file and extract the colors (R,G,B) as a matrix.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using DIB Sections could be way faster than Get/SetPixel, but more complicated. Didn't try it myself, but you could
do something like:
- add LR_CREATEDIBSECTION flag to LoadImage
- Call either (with inputs properly filled):
* GetDIBits
* GetObject(hBmp, SIZEOF(DS), LOC(DS)) where DS is of TYPE(T_DIBSECTION)
- lpvBits argument to GetDIBits (in 1st case) or DS%dsBm%bmBits will point to an array containing bitmap pixels.
It's best to use 32-bit format, because you'll get an array of INTEGER(4) containing bitmap pixels. I don't recall the format -- I think it goes (n,1),(n,2),...(n,m),(n-1,1)...(1,m), where n is height and m width. You can't use it as a matrix, but you could index a 1-d array appropriately.
Jugoslav
do something like:
- add LR_CREATEDIBSECTION flag to LoadImage
- Call either (with inputs properly filled):
* GetDIBits
* GetObject(hBmp, SIZEOF(DS), LOC(DS)) where DS is of TYPE(T_DIBSECTION)
- lpvBits argument to GetDIBits (in 1st case) or DS%dsBm%bmBits will point to an array containing bitmap pixels.
It's best to use 32-bit format, because you'll get an array of INTEGER(4) containing bitmap pixels. I don't recall the format -- I think it goes (n,1),(n,2),...(n,m),(n-1,1)...(1,m), where n is height and m width. You can't use it as a matrix, but you could index a 1-d array appropriately.
Jugoslav

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page