Results 1 to 3 of 3

Thread: getpixel api

  1. #1

    Thread Starter
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650

    getpixel api

    Im used this code and it didnt work. im trying to invert the image

    Public Sub mnuInvert_Click()
    Dim Pixels() As RGBTriplet
    Dim X As Integer
    Dim Y As Integer
    Dim Bits As Integer
    GetPixel Picture1, X, Y
    For X = 0 To Picture1.ScaleWidth
    For Y = 0 To Picture1.ScaleHeight
    With Pixels(X, Y)
    .rgbRed = 255 - .rgbRed
    .rgbGreen = 255 - .rgbGreen
    .rgbBlue = 255 - .rgbBlue
    End With
    Next Y
    Next X
    SetPixel Picture1, X, Y, Bits
    Picture1.Picture = Picture1.Image
    End Sub
    does anyone know why?

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I think it's because you are putting the pset outside of the loops, plus I think you need to use RGB on the Bits variable, don't you? But there is a much quicker easier way if you're interested, try using this API call:

    VB Code:
    1. Public Type RECT
    2.         Left As Long
    3.         Top As Long
    4.         Right As Long
    5.         Bottom As Long
    6. End Type
    7. Public Declare Function InvertRect Lib "user32" Alias "InvertRect" (ByVal hdc As Long, lpRect As RECT) As Long

  3. #3
    Junior Member
    Join Date
    Jul 2002
    Location
    Montreal, Québec
    Posts
    20
    If you really want to stick to the GetPixel and SetPixel commands, try this bit of code...

    for i = 0 to Picture1.ScaleWidth
    for j = 0 to Picture1.ScaleHeight
    c = GetPixel(Picture1.hDC, i, j)
    c = &HFFFFFF - c
    SetPixel(Picture1.hDC, i, j, c)
    next
    next

    Simple as that. You're simply going over every single pixel in the picturebox control, getting their color, calculating the inverted color, and plotting them back. This is considerably slow though. Pixel by pixel plotting takes a rather long time compared to simply using the InvertRect API call.

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