How to save a PNG or BMP transp with Freeimage (solved)

How to save a PNG or BMP transp with Freeimage (solved)

Postby ukoenig » Wed Apr 09, 2014 10:41 am

Hello,
is it possible, to save a Image ( BMP or PNG ) with transparent background ?

The sample shows a merged transparent-logo ( resized to 50 % ) on a transparent image exported to PNG.
I would like to save the main-image as transparent as well.
The exported file shows the transparent area in black.
It is possible, to do this with FREEIMAGE.

Image

From FREEIMAGE documentation a sample :
( how to use this with Fivewin ? )

#include "FreeImage.h"
int main(int argc, char* argv[]) {
FIBITMAP *hDIB24bpp = FreeImage_Load(FIF_BMP, "test.bmp", 0);
if (hDIB24bpp) {
// color-quantize 24bpp (results in a 8bpp bitmap to set transparency)
FIBITMAP *hDIB8bpp = FreeImage_ColorQuantize(hDIB24bpp, FIQ_WUQUANT);
// get palette and find bright green
RGBQUAD *Palette = FreeImage_GetPalette(hDIB8bpp);
BYTE Transparency[256];
for (unsigned i = 0; i < 256; i++) {
Transparency[i] = 0xFF;
if (Palette[i].rgbGreen >= 0xFE &&
Palette[i].rgbBlue == 0x00 &&
Palette[i].rgbRed == 0x00) {
Transparency[i] = 0x00;
}
}
// set the tranparency table
FreeImage_SetTransparencyTable(hDIB8bpp, Transparency, 256);
// save 8bpp image as transparent PNG
FreeImage_Save(FIF_PNG, hDIB8bpp, "test.png", 0);

FreeImage_Unload(hDIB24bpp);
FreeImage_Unload(hDIB8bpp);
}
return 0;
}
FreeImage_SetTransparent

Best regards
Uwe :?:
Last edited by ukoenig on Sat Apr 12, 2014 6:01 pm, edited 2 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: How to save a PNG or BMP transp with Freeimage ?

Postby ukoenig » Sat Apr 12, 2014 5:53 pm

I found a solution, to add / merge a freestyle TRANSPARENT signature
to a image

Image

My new Signature-painter :

Change color and pensize
erase parts of a signature
after erasing, use the last selected color


Image

Best regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: richard-service and 75 guests