Dec 22nd, 2002, 05:15 PM
#1
Thread Starter
Frenzied Member
Some help with pointer...
Hi!
Im using a pointer to plot pixels to a picturebox but i've got 2 problems with this...
1. ifi add + 1 to the colors, it adds more with pointers than with setpixel....(it gets brighter)
2. if i use setpixel, then i cant use the pointer anymore...
Dec 22nd, 2002, 05:23 PM
#2
Thread Starter
Frenzied Member
hmm....wait.....
somethings wrong with this code but i cant figure out what!
VB Code:
For Angle = 0 To 180
TempY = Round(y + Cos(Angle * PiDiv180) * Height)
HighX = Round(x + Sin(Angle * PiDiv180) * Width)
LowX = x - (HighX - x)
If TempY > 0 And TempY < UBound(pic, 2) Then
For TempX = LowX To HighX Step 3
If TempX > 0 And TempX < UBound(pic, 1) - 3 Then
r = pic(TempX + 2, TempY) + 1
g = pic(TempX + 1, TempY) + 1
b = pic(TempX, TempY) + 1
If r > 255 Then r = 255
If r < 0 Then r = 0
If g > 255 Then g = 255
If g < 0 Then g = 0
If b > 255 Then b = 255
If b < 0 Then b = 0
pic(TempX, TempY) = b
pic(TempX + 1, TempY) = g
pic(TempX + 2, TempY) = r
End If
Next
End If
Next
Dec 22nd, 2002, 05:29 PM
#3
Thread Starter
Frenzied Member
fixed the first error (+ some more i just discovered)
i still have the second problem!
heres the new code:
VB Code:
For Angle = 0 To 180
TempY = Round(y + Cos(Angle * PiDiv180) * Height)
HighX = Round(x + Sin(Angle * PiDiv180) * Width)
TempY = UBound(pic, 2) - TempY
LowX = x - (HighX - x)
HighX = HighX * 3
LowX = LowX * 3
If TempY > 0 And TempY < UBound(pic, 2) Then
For TempX = LowX To HighX Step 3
If TempX > 0 And TempX < UBound(pic, 1) - 3 Then
r = pic(TempX + 2, TempY) + 100
g = pic(TempX + 1, TempY) + 1
b = pic(TempX, TempY) + 1
If r > 255 Then r = 255
If r < 0 Then r = 0
If g > 255 Then g = 255
If g < 0 Then g = 0
If b > 255 Then b = 255
If b < 0 Then b = 0
pic(TempX, TempY) = b
pic(TempX + 1, TempY) = g
pic(TempX + 2, TempY) = r
End If
Next
End If
Next
Dec 23rd, 2002, 09:49 AM
#4
Thread Starter
Frenzied Member
i've experienced some crazy things here! i need alot of help i think...
I'll attach the whole code here!
One of the major problems is that i cant paint on any other picture than the one in my program...if i do, it paints wierd!
One other problem is that i cant paint outside the picture but still in the picturebox as i can with setpixel!
Please help me with this!
Attached Files
Dec 24th, 2002, 12:23 PM
#5
Addicted Member
I see what you mean by anti-inter-operability between the two methods.
I got one thing working though
Attached Files
Dec 24th, 2002, 12:53 PM
#6
Addicted Member
the problem you mentioned where it paints weird is due to this:
in order to update a window as quickly as it does, windows likes scanlines to have widthbytes fit 'neatly' with a multiple of 4.
since the picturebox you are working with is using 3 bytes per pixel, not all widths work properly if you're working with a 2d array.
a 1d array loop works like this
WBytes = bmp.bmwidthbytes
TopLeftByte = (bmp.bmheight - 1) * WBytes
BytesPixel = bmp.bmbitspixel / 8
AddWBytes = (bmp.bmwidth - 1) * BytesPixel
For Y = 0 to TopLeft step WBYtes
DrawRight = Y + AddWBytes
For X = Y to Drawright Step BytesPixel
XP2 = x+2
XP1 = x+1
r = buf(xp2)
g = buf(xp1)
b = buf(x)
Last edited by dafhi; Dec 24th, 2002 at 12:57 PM .
Dec 25th, 2002, 11:38 AM
#7
Thread Starter
Frenzied Member
thanks alot for the help!
was the code in the text file only for speeding up?
i dont really get the last code....
could you post what i should change in my code please!
thanks again!
Dec 25th, 2002, 06:18 PM
#8
Addicted Member
that and more critical thinking
this will enhance speed further
dim XP1&
dim XP2&
..
For TempX = LowX To HighX Step 3 'do all x poses in circle (step 3=do one of the colors)
xp1 = tempx+1
xp2 = tempx+2
r = pic(xp2, TempY) ..
g = pic(xp1, TempY) ..
b = pic(TempX, TempY) ..
..
pic(TempX, TempY) = b
pic(Xp1, TempY) = g
pic(Xp2, TempY) = r
Last edited by dafhi; Dec 25th, 2002 at 06:26 PM .
Dec 25th, 2002, 07:20 PM
#9
Addicted Member
I converted what you have to 1d. 1d processing is slightly faster and will work properly with your other true-color bmps
Attached Files
Dec 25th, 2002, 08:02 PM
#10
Thread Starter
Frenzied Member
it still doesnt work with other pictures!
thanks alot for the help!
Dec 26th, 2002, 03:23 AM
#11
Addicted Member
"well that sucks." post one that is messed up if you have the time
Dec 27th, 2002, 12:56 AM
#12
Thread Starter
Frenzied Member
Attached Images
Dec 27th, 2002, 03:06 AM
#13
Addicted Member
it works for me. i have a friend who was having image problems with a 'pointer' anim thing I sent. Different windows versions could be a factor. I did an experiment a while back. Thanks to a fine sub that a great man wrote, I am able to create a picturebox picture in 24 or 32-bit format. I have an older system with a 24 bit graphics card, and the 32 bit formatting works fine. Kudos to the windows team. You may find it worth researching: load a picture into and maintain 32-bit picturebox bit depth
Dec 27th, 2002, 02:59 PM
#14
Thread Starter
Frenzied Member
ok...hmmmmm....
im pretty new to gfx so i dont know exactly how all there things work...all i wanted with the program that i've had some problems with was to learn how to use pointer....
Dec 27th, 2002, 08:15 PM
#15
Addicted Member
if you're working with 24-bit array, widthbytes is the first thing to get a grip on.
if 32-bit, image handling is a snap, except for the fact that PSet and SetPixel, as well as mouse y say that y increases as you move down the form.
Dec 27th, 2002, 10:41 PM
#16
Thread Starter
Frenzied Member
i know how to work with 32-bit pictures in vb using setpixel/getpixel or point/pset...
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