Detect a color device

B

Benjamin Lukner

Hi!

I just became aware that on my b/w Pocket PC device all colors are
transformed to gray if I use e.g. Drawing.Graphics.FillRectangle.
I thought they won't be transformed before the bitmap is written on the
display.

Is this behaviour a feature of .Net (Compact Framework) or depends it on
the graphics driver provided by the manufacturer?

In other words:
Is it possible to detect a b/w device through printing a color (=00FF00)
on a bitmap and compare it with Bitmap.GetPixel() (=555555)?
Is there a better (more failsafe) way to do it?

Kind regards,

Benjamin Lukner
 
C

Chris Tacke, eMVP

It's a driver issue. The best thing to do is query the device capabilities
and ask it how many colors it supports by P/Invoking GetDeviceCaps() with
NUMCOLORS.
 
B

Benjamin Lukner

It's a driver issue. The best thing to do is query the device capabilities
and ask it how many colors it supports by P/Invoking GetDeviceCaps() with
NUMCOLORS.

Thanks, works great!

I'd prefer BITSPIXEL because of the smaller return values ;-)
I get 16 for my color device and 4 for my monochrome device.
But isn't it possible that a device has 8 Bit color or 8 Bit grayscale...?
(I don't think that there are 256 color devices, so "if <= 8" should work)


Source code for VB.Net CF:


Private Declare Function GetDC Lib "coredll.dll" ( _
ByVal hWnd As Int32 _
) As Int32

Private Declare Function ReleaseDC Lib "coredll.dll" ( _
ByVal hWnd As Int32, _
ByVal hDC As Int32 _
) As Int32

Private Declare Function GetDeviceCaps Lib "Coredll.dll" ( _
ByVal hdc As Int32, _
ByVal nIndex As Int32 _
) As Int32

Private Const BITSPIXEL As Int32 = 12
Private Const NUMCOLORS As Int32 = 24
Private Const COLORRES As Int32 = 108


Public Shared ReadOnly Property IsColorDevice() As Boolean
Get

Dim gdc As Int32
Dim iReturn As Integer

gdc = GetDC(Nothing)
iReturn = GetDeviceCaps(gdc, BITSPIXEL)
ReleaseDC(Nothing, gdc)

If iReturn > 8 Then
Return True
Else
Return False
End If

End Get
End Property



Kind regards,

Benjamin Lukner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top