Results 1 to 5 of 5

Thread: picturebox RGB of pixel

  1. #1

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    I need to get the RGB value or Hex color value of all the pixels in a picturebox.
    Thanks,

    ------------------
    DiGiTaIErRoR
    VB, QBasic, Iptscrae, HTML
    Quote: There are no stupid questions, just stupid people.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try the Point() Method, ie.
    Code:
    Private Sub Form_Load()
        Picture1.MousePointer = vbCrosshair
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Caption = Hex$(Picture1.Point(X, Y))
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Certified AllExperts Expert

  3. #3
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161

    Post

    This is another (a little more complicated) way:
    Public Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO_24, ByVal wUsage As Long) As Long
    Public Type RGBQUAD
    rgbBlue As Byte
    rgbGreen As Byte
    rgbRed As Byte
    rgbReserved As Byte
    End Type
    Public Type BITMAPINFOHEADER
    biSize As Long
    biWidth As Long
    biHeight As Long
    biPlanes As Integer
    biBitCount As Integer
    biCompression As Long
    biSizeImage As Long
    biXPelsPerMeter As Long
    biYPelsPerMeter As Long
    biClrUsed As Long
    biClrImportant As Long
    End Type
    Public Type BITMAPFILEHEADER
    bfType As Integer
    bfSize As Long
    bfReserved1 As Integer
    bfReserved2 As Integer
    bfOffBits As Long
    End Type
    Public Type BITMAPINFO_24
    bmiHeader As BITMAPINFOHEADER
    End Type
    Public Const DIB_RGB_COLORS = 0
    Public Const CCHDEVICENAME = 32
    Public Const CCHFORMNAME = 32
    Public Type DEVMODE
    dmDeviceName As String * CCHDEVICENAME
    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmYResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * CCHFORMNAME
    dmUnusedPadding As Integer
    dmBitsPerPel As Long
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
    End Type
    Public pixelbuf() As RGBQUAD
    Public bufsize&
    Public BInfo As BITMAPINFO_24
    Public Max
    Function DIBits(dx, dy, Pdc As Long, PHandle As Long) As Long
    On Error Resume Next
    With BInfo.bmiHeader
    .biSize = 40
    .biWidth = Screen.Width / Screen.TwipsPerPixelX
    .biHeight = Screen.Height / Screen.TwipsPerPixelY
    .biPlanes = 1
    .biBitCount = 32
    .biCompression = 0
    .biClrUsed = 0
    .biClrImportant = 0
    .biSizeImage = bufsize
    End With
    bufsize = dx * dy
    ReDim pixelbuf(0 To bufsize - 1)
    retv = GetDIBits(Pdc, PHandle, 0, BInfo.bmiHeader.biHeight, pixelbuf(0), BInfo, DIB_RGB_COLORS)
    Max = (dx) * (dy) - 1

    DIBits = retv

    End Function

    The pixelbuf array now contains every pixel's RGB Values

    ------------------
    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

  4. #4

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    I need to do it automattically and not under the mouse or whatever. I need the hex value though and not the RGB value.
    Thanks,

    ------------------
    DiGiTaIErRoR
    VB, QBasic, Iptscrae, HTML
    Quote: There are no stupid questions, just stupid people.

  5. #5

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    Ok, well I got all the hex color values now how would I go about repainting the hex values in another picturebox? I'm trying to create a program to store it's images itself so I don't have to use 1 meg BMP's anyone?
    Thanks,

    ------------------
    DiGiTaIErRoR
    VB, QBasic, Iptscrae, HTML
    Quote: There are no stupid questions, just stupid people.

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