Results 1 to 6 of 6

Thread: Picture Box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Montréal, Québec
    Posts
    195

    Picture Box

    Is there a way to retrieve each pixel color (RGB) in a picture box?

    Cause I want to select some pixels (with the mouse) from a picture loaded in a picture box and then retrieve each selected pixel colors to modify it and affect theses pixels to another picture box. Any Idea how to do?

  2. #2
    Lively Member
    Join Date
    Aug 2001
    Posts
    72
    Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function SetPixel Lib "gdi32" Alias "SetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long

    Make sure your Pic's ScaleMode is set to Pixel, then...

    For x = 0 to pic.ScaleWidth - 1
    For y = 0 to pic.ScaleHeight - 1
    lColor = GetPixel(pic.hdc,x,y)
    Setcolor(pic.hdc,x,y,lColor)
    Next y
    Next x

    This code would just set the pixels to the same color they already were, so it's useless, but you get the idea.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Montréal, Québec
    Posts
    195

    !!!!

    Thanks a lot! It Should do quite well the job!

  4. #4
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Hey Megistral, if you're interested in a faster method, I can post it here

    Btw, SetPixelV is faster than SetPixel...
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Montréal, Québec
    Posts
    195

    Thks...

    Thanks Jotaf98 but I've found a new way to Stretch my picture and to set pixel

    To stretch I've used PaintPicture that comes with with the Picture Box (cause I don't need to stretch very often so it's ok) and for setting pixels, I will use BitBlt.


    Is the speed the only difference Between Setpixel and SetpixelV ?

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    The reason it is speedier is because SetPixelV doesn't return anything.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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