How to get the colors of the bits of a bitmap in the clipboad on a system with 65536 colors 
Author Message
 How to get the colors of the bits of a bitmap in the clipboad on a system with 65536 colors

Hi,

I want to get the colors of the bits of a bitmap in the clipboard.
I the system has 16M colors I get 3 bytes for each bit, whihc represents the
color.
On system I get only 2 bytes for each bit. How to get the color value from
that or the R G B values:
And what to do if there is only one byte per pixel?
here a snippet of my code:

Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal
dwCount As Long, lpBits As Any) As Long

sub myfunc()
 Dim bytesperpixel As Long
 Dim bytearray() As Byte
 If Clipboard.GetFormat(2) Then
    Set bmp = Clipboard.GetData(2)
    If bmp.Type = vbPicTypeBitmap Then
        h = Me.ScaleX(bmp.height, vbHimetric, vbPixels)
        w = Me.ScaleY(bmp.width, vbHimetric, vbPixels)
        ReDim bytearray(w * h * 4)
        r = GetBitmapBits(bmp.Handle, w * h * 4, bytearray(0))
        If r > 0 Then
            ReDim Preserve bytearray(r - 1)
            bytesperpixel = r / (w * h)
            If bytesperpixel = 3 Then
                c = RGB(bytearray(p + 2), bytearray(p + 1), bytearray(p))
            ElseIf bytesperpixel = 2 Then
                 ' ???
            ElseIf bytesperpixel = 1 Then
                 '???
            End If
        ...

thank you,
Christoph



Mon, 02 May 2005 02:51:53 GMT  
 How to get the colors of the bits of a bitmap in the clipboad on a system with 65536 colors

Quote:
> I want to get the colors of the bits of a bitmap in the clipboard.
> I the system has 16M colors I get 3 bytes for each bit, whihc represents
the
> color.
> On system I get only 2 bytes for each bit. How to get the color value from
> that or the R G B values:
> And what to do if there is only one byte per pixel?
> here a snippet of my code:

Have a look at the Display info class on my site should be what you're
after.
Otherwise, use the GetDIBits() function and specify what bit depth you're
after.
Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Mon, 02 May 2005 03:24:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Mapping Bitmap Background Colors to System Colors

2. Getting the palette color of a system color

3. how can I retrieve the number of colors/bits per pixel used/avaliable by the system

4. Getting the palette color of a system color

5. Creating bitmap with windows system color

6. Creating bitmap with windows system color

7. System Color Compliant Bitmap.

8. Getting Pixel color from bitmap in VB

9. Getting System Colors

10. Getting SPECIFIC system colors

11. Monochrome bitmap from 256 color bitmap

12. Covert Grayscale Bitmap to Color Bitmap

 

 
Powered by phpBB® Forum Software