CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Posts
    155

    Remove everything but black......

    How do i make it so that when someone clicks a button, it removes every color in a picturebox except for black?

    --Ant
    --------------------------------------------------
    Want a javascript Editor? Visit:
    http://members.fortunecity.com/ants12/jeditdload16.htm
    Or email me:
    [email protected]

  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Remove everything but black......

    You can use the GetPixel API to determine what colo a pixel has, and the setpixel API to change it. However, this needs to check with every pixel, and can take some time with large pictures.

    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

    private Sub Command1_Click()

    Picture1.ScaleMode = 3 ' pixel

    for Y=1 to Picture1.ScaleHeight
    for X=1 to Picture1.ScaleWidth
    If GetPixel(Picture1.hDc, X, Y) <> 0 then
    ' not black, so set it red
    SetPixel Picture1.hDc, X, Y, RGB(255,0,0)
    End If
    next X
    next Y

    End Sub




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured