|
-
Jun 5th, 2002, 10:06 AM
#1
Thread Starter
Lively Member
Get Long Pixel Value
Hi everyone.
I need to get long pixel values out of a bitmap. I need to do this
for many, many pixels at once so GetPixel API is not feasible. I
found some GetDIBits and CreateDIBSection samples that seem
to do what I want, but they automatically retrieve the pixel
values into R, G, and B Byte values. I have tried to manipulate
the samples to get the long values, but to no avail. Can some
kind soul please post some sample code that gets long values
from a DIB?
Otherwise, does someone know how to get a long value
from RGB values?
Thanks, if you can help.
-
Jun 5th, 2002, 10:20 AM
#2
Fanatic Member
The RGB function lets you pass in R, G, and B to get a long color.
-
Jun 5th, 2002, 11:08 AM
#3
Thread Starter
Lively Member
Gaming-world:
Thanks! -- I should have known that such a function was
available! It'll do as a good band-aid solution to my problem (it
adds only a few milliseconds); I'll figure out how to get long
values directly at some point later. Again, if anyone else has
any ideas, I'd still appreciate them...
Thanks
-
Jun 5th, 2002, 02:53 PM
#4
Good Ol' Platypus
The actual formula is R + G * 256 + B * 256 ^ 2. I don't think you'll get any more speed, and usually byte results are preferable... what are you doing that makes you want longs?
It might be the other way (R * 256 ^ 2 + G * 256 + B). I'm a bit rusty there.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jun 5th, 2002, 04:42 PM
#5
Thread Starter
Lively Member
Sastraxi:
Thanks for replying. I know from your other posts on this board
that you know your graphics stuff.
Since you asked...
I need to access long values and not colors, per se, because I'm
not treating the bitmaps as graphics, but using them to store
data (actually population levels) that need to be expressed as
long values.
Thanks for the formula behind the RGB function. I always
appreciate understanding the stuff I use.
-
Jun 6th, 2002, 07:37 AM
#6
Good Ol' Platypus
Well, I believe a faster way would be using the CopyMemory API:
VB Code:
'// bmBits(3x + c, y) is the array that holds the byte values. 3x + c for the 24-bit nature (rgbrgbrgbrgb) of holding the bytes.
CopyMemory LV, bmBits(x * 3, y), 3
'//LV should now store your long value
If it doesn't work, you could try LSet, but I'm not sure if you can use parts of arrays with it.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jun 7th, 2002, 10:59 AM
#7
Addicted Member
Here's a fast, pure-vb method:
VB Code:
Public Type LongUDT
Value as Long
End Type
Public Type BGRAUDT
Blue as Byte
Green as Byte
Red as Byte
Alpha as Byte
End Type
Dim LU as LongUDT, Color as BGRAUDT
' ...
LU.Value = GetPixel(Me.hDC, X, Y)
LSet Color = LU
Color.Blue = Color.Blue \ 2
Color.Green = Color.Green \ 2
Color.Red = Color.Red \ 2
LSet LU = Color
Call SetPixelV(Me.hDC, X, Y, LU.Value)
' ...
It's faster than copymemory (though only like 5%), and it doesn't require API declarations. It's a little cumbersome, though.
"1 4m 4 1337 #4xz0r!'
Janus
-
Jun 9th, 2002, 05:06 AM
#8
Frenzied Member
Hey Janus do you mind to explain why that works? (especially the dividing by two)
and Heva, is it neccersary for you to store the data in a bitmap? I believe there is a bunch of unused infos saved... why not use a two dimensional array? (do you use RLE?)
Sanity is a full time job
Puh das war harter Stoff!
-
Jun 9th, 2002, 10:38 AM
#9
Good Ol' Platypus
Janus, he wanted to use it with GetDIBits and those kind of calls. In this case, I don't think you CAN use LSet (I haven't tried, but correct me if I'm wrong).
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jun 9th, 2002, 10:39 AM
#10
Good Ol' Platypus
Misanthrop; Janus' code simply halves the brightness of an image (hence the / 2).
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jun 9th, 2002, 10:54 AM
#11
Frenzied Member
alright now I feel much better
(you help me a lot today sastraxi )
Sanity is a full time job
Puh das war harter Stoff!
-
Jun 9th, 2002, 02:34 PM
#12
Addicted Member
You can use any kind of array for GetDIBits - just pass it like this:
Code:
GetDIBits([blah blah], ByVal VarPtr(PixelArray(0,0)), [blah blah])
I do it all the time.
"1 4m 4 1337 #4xz0r!'
Janus
-
Jun 9th, 2002, 03:23 PM
#13
Good Ol' Platypus
But can you use Lset like this?
VB Code:
Dim A(x,x) as UdtPixel
Dim Col as UdtRGB
GetDIBits(...) 'whatever
LSet Col = A(0, 0) 'will this bomb out or take the values from (0-3, 0)?
That's what I'm getting at, Janus.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jun 10th, 2002, 12:40 AM
#14
Addicted Member
LSet copies sizeof(dest) bytes from source.
"1 4m 4 1337 #4xz0r!'
Janus
-
Jun 10th, 2002, 07:15 AM
#15
Good Ol' Platypus
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jun 19th, 2002, 09:26 AM
#16
Thread Starter
Lively Member
THANKS.
Sastraxi, Janus, /\/\isanThr0p:
Sorry that I neglected this thread for a while ... thanks for your
ideas. I've already learned plenty from each of you, and I'm
investigating what I don't yet understand. To answer your
question /\/\isanThr0p, I do need to store the data graphically
because the bitmaps are Maps that we'll need to view from time
to time, but your point is a valid one, and I had considered
using a pure array for the speed benefits. But working with
GetDIBits and CopyMemory has given me access to the pixels
in array form, and it seems to be extremely fast. But I'm still
looking for the best method, as speed matters. Once again,
thanks ... as far as I'm concerned, you're all elevated to Oracle
status.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|