qwert Posted August 9, 2017 Share Posted August 9, 2017 I'm loading a PNG with transparency into a pic control. The load works fine and the transparency is honored. I'm then converting the image and writing to a JPG file. Again, the conversion and write work fine, but I have one problem with the result: The transparent areas convert to black. I need them to be white. Would anyone happen to know what parameter controls the background color during the conversion to JPG? Thanks in advance for any help. Here are the key statements involved in the load and conversion: $hBitmap = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) ; $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) DllCall($__g_hGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode) _GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $sImage, 0, 0, $iWidth, $iHeight) ; _GDIPlus_ImageSaveToFile($hBitmap, $toFile) Link to comment Share on other sites More sharing options...
Malkey Posted August 9, 2017 Share Posted August 9, 2017 Try:- _GDIPlus_GraphicsClear($hBmpCtxt, 0xFFFFFFFF) ;clear bitmap with color white Ref: _GDIPlus_BitmapCreateFromScan0 function in AutoIt help file. Link to comment Share on other sites More sharing options...
genius257 Posted August 9, 2017 Share Posted August 9, 2017 crazy alternative: #include <GDIPlus.au3> _GDIPlus_Startup() $hBMP = _GDIPlus_BitmapCreateFromScan0(100, 100, $GDIP_PXF32PARGB) Local $hIA = _GDIPlus_ImageAttributesCreate() ;create an ImageAttribute object $t=DllStructCreate("UINT[2]") DllStructSetData($t,1,0x00000000,1) DllStructSetData($t,1,0xFFFFFFFF,2) DllCall($__g_hGDIPDll, "uint", "GdipSetImageAttributesRemapTable", "handle", $hIA, "int", 0, "int", 1, "int", 1, "struct*", $t) $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBMP) _GDIPlus_GraphicsSetCompositingMode($hGraphics, 1) _GDIPlus_GraphicsClear($hGraphics, 0x0) $hBrush=_GDIPlus_BrushCreateSolid(0xFF00000) _GDIPlus_GraphicsFillRect($hGraphics, 10, 10, 80, 80, $hBrush) _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBMP, 0, 0, 100, 100, 0, 0, 100, 100, $hIA) _GDIPlus_ImageSaveToFileEx($hBMP, "output.jpg", _GDIPlus_EncodersGetCLSID("JPG")) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBMP) _GDIPlus_ImageAttributesDispose($hIA) _GDIPlus_Shutdown() My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now