Jump to content
Sign in to follow this  

Conversion problem on PNG w/transparency

Recommended Posts


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

crazy alternative:

#include <GDIPlus.au3>

$hBMP = _GDIPlus_BitmapCreateFromScan0(100, 100, $GDIP_PXF32PARGB)
Local $hIA = _GDIPlus_ImageAttributesCreate() ;create an ImageAttribute object
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)

_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"))



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