Re: image to 2D-long-array
I don't understand your problem but geting right pixels is something like this
Code:
Declare Function GetPixel Lib "gdi32.dll" ( _
ByVal hdc As Long, _
ByVal x As Long, _
ByVal y As Long) As Long
dim Pixel(512,512) as long 'insted 512 set width and height of region
dim RightPixels(512,512) as boolean
sub GetRightPixels(color as long)
for i=1 to 512
for j=1 to 512
Pixel(i,j)=GetPixel(picture1.hdc,i,j) ' set scale to pixels in properties of your form and picturebox
if Pixel(i,j)=color then rightpixels(i,j)=True
next j
next i
end sub
Re: image to 2D-long-array
Hm...
Is that the fastest method? Cause I really need to have a fast method?
And if I have the right pixels? How can I make a region out of that?
Re: image to 2D-long-array
Well there are faster, but more complicated, tehnicques:
First, declare functions and types
Code:
Private Type Bitmap
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
dim rightpixels(0 to 512,0 to 512) as boolean 'instead 512 w-1 and h-1 :-)
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, ByRef lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, ByRef lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, ByRef lpBits As Any) As Long
Now, you can get pixels more faster than with getpixel by this proc:
Code:
sub getrightpixels(color)
dim bm As bitmap
getobject picture1.image, len(bm), bm
dim pixeldata() as Byte 'byte beacuse you will get each of R,G, and B components
redim pixeldata(0 To (bm.bmBitsPixel \ 8) - 1, 0 To bm.bmWidth - 1, 0 To bm.bmHeight - 1) 'first dimension of array is 0=red, 1=green, 2=blue , second is x, and third is y
getbitmapbits picture1.image, bm.bmWidthBytes * bm.bmHeight, pixeldata(0, 0, 0) 'getting pixels
for i=0 to bm.bmWidth-1
for j=0 to bm.bmHeight-1
if RGB(pixeldata(0,i,j),pixeldata(1,i,j),pixeldata(2,i,j))=color then rightpixel(i,j)=true
next j
next i
end sub
I hope you understand this :)
About regions i don't know very much, but i will find out :afrog:
Re: image to 2D-long-array
Yeah, I already knew about that procedure, but I have a slow computer. And it's for a game, to set up a world. And I want that to happen as fast as possible. So That's why I wanted to use a long-array instead of a byte-array cause long is faster than byte.
Maybe I should rephrase the question: "What's the fastest method to create a region of a color in a bitmap?"
Re: image to 2D-long-array
There isn't any faster method than Getpixel in VB :cry:.
If you know C or C++, you can write an dll for faster, and long type data.
Re: image to 2D-long-array