Jump to content
Sign in to follow this  
JScript

How to create a bitmap with 8 bits (256 colors), not grayscale!

Recommended Posts

JScript

Hello friends!

I already know how to make 8-bit grayscale using _WinAPI_CreateDIBSection() function, but unfortunately I could not understand well and I do not know if it is possible to obtain the results posted on this link:
http://en.wikipedia.org/wiki/Color_depth # 8-bit_color

I appreciate any help,

JS


http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites
UEZ

Do you want to create an empty 8-bit bitmap or convert an image to 8-bit image?

1) Create an empty 8-bit bitmap -> _GDIPlus_BitmapCreateFromScan0() using $GDIP_PXF08INDEXED as the pixel format

2) Check out _GDIPlus_BitmapConvertFormat() function in the help file

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
JScript

Hello, thanks for the reply, but do not actually need to convert, note the code below:

$iBitCount = 8

$hSrcDC = _WinAPI_GetDC(_WinAPI_GetDesktopWindow())
$hDestCDC = _WinAPI_CreateCompatibleDC(0)

$tBMPINFO = DllStructCreate("dword Size; long Width; long Height; word Planes; word BitCount; dword Compression; dword SizeImage; long XPelsPerMeter; long YPelsPerMeter; dword ClrUsed; dword ClrImportant; dword RGBQuad[256];")
DllStructSetData($tBMPINFO, "Size", 40);DllStructGetSize($tBITMAPINFO) - 4);
DllStructSetData($tBMPINFO, "Planes", 1)
DllStructSetData($tBMPINFO, 'Compression', 0);$BI_RGB)
DllStructSetData($tBMPINFO, 'SizeImage', 0)
DllStructSetData($tBMPINFO, "Width", $iWidth)
DllStructSetData($tBMPINFO, "Height", -($iHeight)); minus =standard = bottomup
DllStructSetData($tBMPINFO, "BitCount", $iBitCount)
If $iBitCount <= 8 Then
    $iColorCnt = BitShift(1, -$iBitCount)
    DllStructSetData($tBMPINFO, 'ClrUsed', $iColorCnt)
    DllStructSetData($tBMPINFO, 'ClrImportant', $iColorCnt)
EndIf
Switch $iBitCount
    Case 8
        For $i = 0 To $iColorCnt - 1
            DllStructSetData($tBMPINFO, 'RGBQuad', BitOR(BitShift($i, -16), BitShift($i, -8), $i), $i + 1)
        Next
    Case 4
        Local $aCol[16] = [8, 24, 38, 56, 72, 88, 104, 120, 136, 152, 168, 184, 210, 216, 232, 248]
        For $i = 0 To 15
            DllStructSetData($tBMPINFO, 'RGBQuad', BitOR(BitShift($aCol[$i], -16), BitShift($aCol[$i], -8), $aCol[$i]), $i + 1)
        Next
    Case 1
        DllStructSetData($tBMPINFO, 'RGBQuad', BitOR(BitShift(0xFF, -16), BitShift(0xFF, -8), 0xFF), 2)
EndSwitch

$hHBitmap = _WinAPI_CreateDIBSection($hDestCDC, $tBMPINFO, $DIB_RGB_COLORS, $pBits)
_WinAPI_SelectObject($hDC, $hHBitmap)

_WinAPI_StretchBlt($hDestCDC, $iWndX, $iWndY, $iWndW, $iWndH, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $SRCCOPY)
In this way I can take a screen shot on 8 bits but unfortunately is in shades of gray!

 

How to get a colored with only 256 colors as shown in this link http://en.wikipedia.org/wiki/Color_depth?

 

Edit1:

Sample image of 8 bit (256 colors):

8_bit.png

Edit2:

After playing a bit with the "bmiColors" I got this result:

XTAZBsR.png

But you may notice that the color white is "saturated", as well as the black color is also!

Edit3:

After some testing, the maximum I got was this result:

UC1fvV4.png

But I'm not sure that is correct because I'm Colorblind...

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites
UEZ

It looks good (edit 3 screenshot).

You need it for your RDP app, right? If yes, then GDI+ might be the wrong choice. GDI is faster.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
JScript

It looks good (edit 3 screenshot).

You need it for your RDP app, right? If yes, then GDI+ might be the wrong choice. GDI is faster.

Br,

UEZ

Yes is for my remote desktop program! Interesting to know that the bitmap has the same size if it is in grayscale!

I use Bitmap cache that minimizes the amount of bitmap data transferred between the client and server. The client creates an compressed, temporary bitmap cache that contains bitmaps that are repeatedly sent from the server to the client.

The client uses GDI calls and these cached bitmaps to draw onto the display. The cache resides in RAM and is valid for the session.

When the code is complete I'll post for you to see,

Edit1:

Another variation. Better result?

Pno0R8T.png

Edit2:

See VNC with 256 colors to the left of the picture and my program in the right of the image:

9m2QLsG.png

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites
UEZ

Edit1 is dithered but I like more your Edit2 result.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
JScript

Edit1 is dithered but I like more your Edit2 result.

Br,

UEZ

Thank you friend!

Based on the explanations of these two links:

http://msdn.microsoft.com/en-us/library/bb250466%28VS.85%29.aspx#safety_topic2

https://www.gidforums.com/t-21296.html

I got the final conclusion, see:

Capture with 8bits and SetStretchBltMode in COLORONCOLOR:

eNV7LPL.png

Capture with 8bits and SetStretchBltMode in HALFTONE:

9sJDxMp.png

JS


http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×