Création PNG transparent (French)

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, helmut, xnview

alex1er
Posts: 44
Joined: Tue Sep 07, 2004 9:09 am

Création PNG transparent (French)

Post by alex1er »

Bonjour,

j'aimerais reussir à collé une vignette (120*90) dans un bitmap carre (120*120), qui soit centré et dont les bord hors vignette soient transparents.

J'ai essayé de le codé avec le code ci-dessous mais les bords ne sont toujours pas transparents.

Code: Select all

        GFL_BITMAP * GFL_tmp;
	int max = width;
	int xDest;
	int yDest;
	GFL_RECT rect;
	GFL_COLOR color;
	
//centrage de l'image
	if (height > width)
	{
		max = height;
		yDest = 0;
		xDest = (height - width)/2;
	}
	else
	{
		yDest = (width - height)/2;
		xDest = 0;
	}
		
	//Création du Bitmap vide
	color.Red=255;
	color.Blue=255;
	color.Green=255;
	color.Alpha=0;
					
	GFL_tmp = gflAllockBitmap(GFL_RGBA,
					max,
					max,
					4,
					&color);					
	//On redimentionne le bitmap
	ResizeImage();
	
	rect.x = 0;
	rect.y = 0;
	rect.w = width;
	rect.h = height;
	

	//Copie de l'image mini dans le carre
	gflBitblt(GFL_Image,
			&rect,
			GFL_tmp,
			xDest,
			yDest);
	GFL_Image = gflCloneBitmap(GFL_tmp);
	
	
	//Creation du contour de l'image
	color.Red=0;
	color.Blue=0;
	color.Green=0;
	DrawRectangleColor(max, max, &color);
		
	//Sauvegarde de l'image PNG
	SaveImageJPG(_compress_);
	
	//Supression du BMP temporaire
	gflFreeBitmap(GFL_tmp);
une petite idée?

merci
User avatar
xnview
Author of XnView
Posts: 45062
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Création PNG transparent

Post by xnview »

alex1er wrote:j'aimerais reussir à collé une vignette (120*90) dans un bitmap carre (120*120), qui soit centré et dont les bord hors vignette soient transparents.
Le plus simple est de faire:

Code: Select all

GFL_BITMAP * tmp, * bitmap;
GFL_RECT rect;
GFL_COLOR color;
GFL_ERROR error; 
   
   color.Red=255;
   color.Blue=0;
   color.Green=0;
   color.Alpha=0;
   bitmap = gflAllockBitmap(GFL_RGB,
               60,
               60,
               4,
               &color);    

   color.Red=0;
   color.Blue=255;
   color.Green=0;
   color.Alpha=255;
   tmp = gflAllockBitmap(GFL_RGBA,
               120,
               120,
               4,
               &color);   
	rect.x = rect.y = 0; 
	rect.w = bitmap->Width; 
	rect.h = bitmap->Height; 
	error=gflBitblt(bitmap, &rect, tmp,20,20); 
Pierre.
alex1er
Posts: 44
Joined: Tue Sep 07, 2004 9:09 am

Post by alex1er »

Je vais essayer ca.

merci