Jump to content
Sign in to follow this  
qwert

Conversion problem on PNG w/transparency

Recommended Posts

qwert

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)

Conversion to JPG.jpg

Share this post


Link to post
Share on other sites
genius257

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()

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.