Click to See Complete Forum and Search --> : GetPixel Problems...
Jigabug
Jun 20th, 2002, 11:25 PM
Hey,
I'm using the GetPixel function to read every pixel in an image, then write it to a text file... that's been pretty simple. But after a bit of time it seems to just give up and starts spewing out either red (255) or an error (-1), any ideas?
wazup guys
Jun 21st, 2002, 02:56 AM
i would need to see what the image looks like and your code
Jigabug
Jun 21st, 2002, 06:37 AM
OK, it happens on all sorts of images, not just one..... Seems to affect large images more though...
and code?
Option Explicit
Dim i%, j%, col&
Private Sub Form_Load()
picw = 23 'Set picture width in pixels
pich = 30 'Set picture height in pixels
End Sub
Private Sub Command1_Click()
For i = 0 To pich - 1
For j = 0 To picw - 1
col = GetPixel(picPicture.hdc, j, k)
Text1.Text = Text1.Text & col & vbCrLf
Next j
Next i
Yhoko
Jun 21st, 2002, 11:03 AM
Did you set picPicture.AutoRedraw to True? I think this may be your mistake...
Jigabug
Jun 21st, 2002, 03:27 PM
It is set to true, has been the whole time. I didn't think it would make a difference because of it being GetPixel.... bu it's set to true.
Knowledge_is_Et
Jun 21st, 2002, 03:46 PM
I've had similar problems. Getpixel uses a pixel scale. Maybe the scale is different?
wazup guys
Jun 21st, 2002, 09:30 PM
ok time for some working code
sub [were you need the code]
dim x,y,temp as long
open "c:\data.txt" for output as #1
for y = 0 to picture1.scalehieght
for x = 0 to picture1.scalewidth
temp = picture1.point(x,y)
print #1, temp
doevents
next x
next y
close #1
end sub
you can put the code in the sub rutien you need it
if your going to be doing it to alot of images i suggest that u have a image box and load the image first to the image box and transfer the width and hieght to the picture box and the picture box should have sclaemode of 3-pixel.
just incase whats you email so i can email a vb project to you if it doesnt work
Jigabug
Jun 22nd, 2002, 07:36 AM
My email? Type some random letters in.... any will do... then add @jigabug.net to it and it'll get to me...
I'll let you know how it works...
Update: Works great, I had to add a -1 to the end of these two lines in order to avoid it generating a -1, but other then that it works perfectly. Thanks again!
For y = 0 To Picture1.ScaleHeight
For x = 0 To Picture1.ScaleWidth
Arbiter
Jun 22nd, 2002, 07:46 AM
I've highlighted a bit in bold for you....
Option Explicit
Dim i%, j%, col&
Private Sub Form_Load()
picw = 23 'Set picture width in pixels
pich = 30 'Set picture height in pixels
End Sub
Private Sub Command1_Click()
For i = 0 To pich - 1
For j = 0 To picw - 1
col = GetPixel(picPicture.hdc, j, k)
Text1.Text = Text1.Text & col & vbCrLf
Next j
Next i
Yhoko
Jun 22nd, 2002, 07:57 AM
*smiles* Sorry didn't see that. Jigabug I highly recommend you to use the 'Option Explicit' statement in any of your modules so you don't get into this problem again.
Arbiter
Jun 22nd, 2002, 08:10 AM
The interesting thing is that he has.
He must have it declared globally somewhere else...
I've just noticed he's edited his post above to say that he's got it sorted. He's using point, so it will be slower - but hey, as long as it works.....
Jigabug
Jun 22nd, 2002, 08:36 AM
Yes,
All of the variables used in the program are globally declared along with a whole bunch of functions in a module that must be 75 pages or more of code... That code was just the snippit causing problems.
The other thing is that it's still not working right on larger images, it handles the 100x100 fine now, but i have a 340x480 image that I need it to be able to work on, and it freezes. Any ideas?
Another thing, Yhoko hit one nail on the head, when I set autoredraw to true it was the form, not the picture... The GetPixel option works now, but I'm not sure which would be faster...
wazup guys
Jun 22nd, 2002, 06:44 PM
if you can get getpixel to work right it will be faster just by a couple of seconds. could you possibly email it to me to see it to see whats going wrong
wazup guys
Jun 22nd, 2002, 07:09 PM
although my code isn't 75 pages long i just timed it on a 800x600 image and it took me 4 secs i dont think thats to long.
what is picture.scalemode set to.
Jigabug
Jun 22nd, 2002, 07:24 PM
Wazup,
a) You're not getting your hands on the code.
b) I have them both working now
c) 4 seconds? Using which method?
wazup guys
Jun 22nd, 2002, 07:35 PM
4 secs using point on a 800 x 600 pixel image
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.