Results 1 to 16 of 16

Thread: Some help with pointer...

  1. #1

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    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...
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  2. #2

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    hmm....wait.....
    somethings wrong with this code but i cant figure out what!

    VB Code:
    1. For Angle = 0 To 180
    2.         TempY = Round(y + Cos(Angle * PiDiv180) * Height)
    3.         HighX = Round(x + Sin(Angle * PiDiv180) * Width)
    4.         LowX = x - (HighX - x)
    5.         If TempY > 0 And TempY < UBound(pic, 2) Then
    6.             For TempX = LowX To HighX Step 3
    7.                 If TempX > 0 And TempX < UBound(pic, 1) - 3 Then
    8.                     r = pic(TempX + 2, TempY) + 1
    9.                     g = pic(TempX + 1, TempY) + 1
    10.                     b = pic(TempX, TempY) + 1
    11.                     If r > 255 Then r = 255
    12.                     If r < 0 Then r = 0
    13.                     If g > 255 Then g = 255
    14.                     If g < 0 Then g = 0
    15.                     If b > 255 Then b = 255
    16.                     If b < 0 Then b = 0
    17.                     pic(TempX, TempY) = b
    18.                     pic(TempX + 1, TempY) = g
    19.                     pic(TempX + 2, TempY) = r
    20.                 End If
    21.             Next
    22.         End If
    23.     Next
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  3. #3

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    fixed the first error (+ some more i just discovered)
    i still have the second problem!

    heres the new code:

    VB Code:
    1. For Angle = 0 To 180  
    2.         TempY = Round(y + Cos(Angle * PiDiv180) * Height)
    3.         HighX = Round(x + Sin(Angle * PiDiv180) * Width)
    4.         TempY = UBound(pic, 2) - TempY
    5.         LowX = x - (HighX - x)
    6.         HighX = HighX * 3
    7.         LowX = LowX * 3
    8.         If TempY > 0 And TempY < UBound(pic, 2) Then
    9.             For TempX = LowX To HighX Step 3
    10.                 If TempX > 0 And TempX < UBound(pic, 1) - 3 Then
    11.                     r = pic(TempX + 2, TempY) + 100
    12.                     g = pic(TempX + 1, TempY) + 1
    13.                     b = pic(TempX, TempY) + 1
    14.                     If r > 255 Then r = 255
    15.                     If r < 0 Then r = 0
    16.                     If g > 255 Then g = 255
    17.                     If g < 0 Then g = 0
    18.                     If b > 255 Then b = 255
    19.                     If b < 0 Then b = 0
    20.                     pic(TempX, TempY) = b
    21.                     pic(TempX + 1, TempY) = g
    22.                     pic(TempX + 2, TempY) = r
    23.                 End If
    24.             Next
    25.         End If
    26.     Next
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    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 Attached Files
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  5. #5
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    I see what you mean by anti-inter-operability between the two methods.

    I got one thing working though
    Attached Files Attached Files

  6. #6
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    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.

  7. #7

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    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!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  8. #8
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    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.

  9. #9
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    I converted what you have to 1d. 1d processing is slightly faster and will work properly with your other true-color bmps
    Attached Files Attached Files

  10. #10

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    it still doesnt work with other pictures!

    thanks alot for the help!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  11. #11
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    "well that sucks." post one that is messed up if you have the time

  12. #12

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    try with this pic:
    Attached Images Attached Images  
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  13. #13
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    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

  14. #14

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    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....
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  15. #15
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    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.

  16. #16

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    i know how to work with 32-bit pictures in vb using setpixel/getpixel or point/pset...
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width