|
-
Jun 20th, 2002, 11:25 PM
#1
Thread Starter
Lively Member
GetPixel Problems...
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?
To err is human, to really mess up, you need a computer.
-
Jun 21st, 2002, 02:56 AM
#2
Lively Member
i would need to see what the image looks like and your code
-
Jun 21st, 2002, 06:37 AM
#3
Thread Starter
Lively Member
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
To err is human, to really mess up, you need a computer.
-
Jun 21st, 2002, 11:03 AM
#4
Member
Did you set picPicture.AutoRedraw to True? I think this may be your mistake...
-
Jun 21st, 2002, 03:27 PM
#5
Thread Starter
Lively Member
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.
To err is human, to really mess up, you need a computer.
-
Jun 21st, 2002, 03:46 PM
#6
Hyperactive Member
I've had similar problems. Getpixel uses a pixel scale. Maybe the scale is different?
Now returning to the world of VB. Please make sure your seatbelts are securely fastened and all trays are in their upright and locked position.
-
Jun 21st, 2002, 09:30 PM
#7
Lively Member
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
-
Jun 22nd, 2002, 07:36 AM
#8
Thread Starter
Lively Member
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
Last edited by Jigabug; Jun 22nd, 2002 at 07:43 AM.
To err is human, to really mess up, you need a computer.
-
Jun 22nd, 2002, 07:46 AM
#9
PowerPoster
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
Gentile or Jew,
O you who turn the wheel and look to windward,
Consider Phlebas, who was once handsome and tall as you...
-
Jun 22nd, 2002, 07:57 AM
#10
Member
*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.
-
Jun 22nd, 2002, 08:10 AM
#11
PowerPoster
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.....
Gentile or Jew,
O you who turn the wheel and look to windward,
Consider Phlebas, who was once handsome and tall as you...
-
Jun 22nd, 2002, 08:36 AM
#12
Thread Starter
Lively Member
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...
To err is human, to really mess up, you need a computer.
-
Jun 22nd, 2002, 06:44 PM
#13
Lively Member
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
-
Jun 22nd, 2002, 07:09 PM
#14
Lively Member
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.
-
Jun 22nd, 2002, 07:24 PM
#15
Thread Starter
Lively Member
Wazup,
a) You're not getting your hands on the code.
b) I have them both working now
c) 4 seconds? Using which method?
To err is human, to really mess up, you need a computer.
-
Jun 22nd, 2002, 07:35 PM
#16
Lively Member
4 secs using point on a 800 x 600 pixel image
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
|