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?
Printable View
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?
i would need to see what the image looks like and your code
OK, it happens on all sorts of images, not just one..... Seems to affect large images more though...
and code?
VB 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
Did you set picPicture.AutoRedraw to True? I think this may be your mistake...
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.
I've had similar problems. Getpixel uses a pixel scale. Maybe the scale is different?
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
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!
VB Code:
For y = 0 To Picture1.ScaleHeight For x = 0 To Picture1.ScaleWidth
I've highlighted a bit in bold for you....
VB 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, [b]k[/b]) Text1.Text = Text1.Text & col & vbCrLf Next j Next i
*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.
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.....
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...
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
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.
Wazup,
a) You're not getting your hands on the code.
b) I have them both working now
c) 4 seconds? Using which method?
4 secs using point on a 800 x 600 pixel image