|
-
Apr 30th, 2007, 06:52 AM
#1
Thread Starter
Member
image to 2D-long-array
I have an image in a picturebox loaded with bitblt. Now I want to get the region of a color in that image. So I thought, if I could get all the pixels in a 2D-long-array I could go through all of them to see wich pixels have the right color so I can make a region.
But, how can I get all the pixels into a 2D-pixel-array?
Or does someone know a faster way to get the region of a color?
-
Apr 30th, 2007, 12:31 PM
#2
New Member
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
-
Apr 30th, 2007, 01:11 PM
#3
Thread Starter
Member
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?
-
Apr 30th, 2007, 02:32 PM
#4
New Member
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
-
May 1st, 2007, 04:13 AM
#5
Thread Starter
Member
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?"
-
May 1st, 2007, 05:02 AM
#6
-
May 1st, 2007, 06:30 AM
#7
Thread Starter
Member
Re: image to 2D-long-array
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
|