Jump to content

Recommended Posts

Posted

Well I try to set a color for a bitmap pixels and when I read them I got new colors. Is that because of color format?

#include <GDIPlus.au3>

_GDIPlus_Startup()

; Create a HBITMAP
$hHBITMAP = _WinAPI_CreateBitmap(200,200,1,32)
; Create a bitmap
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBITMAP)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
; Set pixels color 0xFCFF0000
_GDIPlus_GraphicsClear($hContext,0xFCFF0000)

; In this phase the color is 0xFFFC0000
ConsoleWrite(GetPixel($hBitmap,10,10) & @CRLF)

; Create a bitmap clone in format ARGB
$hClone = _GDIPlus_BitmapCloneArea($hBitmap,0,0,200,200,$GDIP_PXF32ARGB)
$hCloneContext = _GDIPlus_ImageGetGraphicsContext($hClone)
; Set pixels color 0xFCFF0000
_GDIPlus_GraphicsClear($hCloneContext,0xFCFF0000)

; In this phase the color is 0xFCFE0000
ConsoleWrite(GetPixel($hClone,10,10) & @CRLF)


; Clean up resources
_GDIPlus_GraphicsDispose($hCloneContext)
_GDIPlus_BitmapDispose($hClone)
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject($hHBITMAP)

_GDIPlus_Shutdown()

Func GetPixel($hBitmap,$X,$Y)
    Local $tPixel = DllStructCreate("dword Pixel")
    DllCall($ghGDIPDll,"int","GdipBitmapGetPixel","handle",$hBitmap,"int",$X,"int",$Y,"ptr",DllStructGetPtr($tPixel))
    Return Hex(DllStructGetData($tPixel,"Pixel"),8)
EndFunc
Posted

Seems to be that this bitmap format (also DDB) is not alpha channel compatible. Why you create a GDI bitmap and want to use it with GDI+ instead of creating a GDI+ bitmap directly?

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

Because of lack of a function to create a bitmap with given width and height. Anyway, then I create a new bitmap using GDI+, can be this the problem?

Edit:

1. When pixels color are set by _GDIPlus_GraphicsClear() the color is different.

2. When pixels are set by GdipBitmapSetPixel() it's good.

#include <GDIPlus.au3>

_GDIPlus_Startup()

; Create a bitmap
$hBitmap = DllCall($ghGDIPDll,"uint","GdipCreateBitmapFromScan0","int",100,"int",100,"int",0,"int",$GDIP_PXF32ARGB,"ptr",0,"int*",0)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap[6])
; Set pixels color 0xFCFF0000
_GDIPlus_GraphicsClear($hContext,0xFCFF0000)

; In this phase the color is 0xFCFE0000
ConsoleWrite(GetPixel($hBitmap[6],10,10) & @CRLF)

; Set Pixel(10,10) color: 0xFCFF0000
DllCall($ghGDIPDll,"int","GdipBitmapSetPixel","handle",$hBitmap[6],"int",10,"int",10,"dword",0xFCFF0000)

; In this phase the color is 0xFCFF0000
ConsoleWrite(GetPixel($hBitmap[6],10,10) & @CRLF)

; Clean up resources
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_BitmapDispose($hBitmap[6])

_GDIPlus_Shutdown()

Func GetPixel($hBitmap,$X,$Y)
    Local $tPixel = DllStructCreate("dword Pixel")
    DllCall($ghGDIPDll,"int","GdipBitmapGetPixel","handle",$hBitmap,"int",$X,"int",$Y,"ptr",DllStructGetPtr($tPixel))
    Return Hex(DllStructGetData($tPixel,"Pixel"),8)
EndFunc
Edited by Andreik
Posted

I cannot say whether this is a feature or a bug because clearing the gfx with 0xF0FF0000 returns true values again.

That's really strange...

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...