二进制流图像png8透明背景压缩

/* pTempPngbuffer是unsigned char*类型的二进制图像,nSize是其长度*/

gdImagePtr bpp,bpp8;

int alpha;


//read png32 from a buffer in memory

bpp=gdImageCreateFromPngPtr(nSize,pTempPngbuffer);


//change the alpha allocate parameters if needed

bpp8=gdImageCreateTrueColor(mWidth,mHeight);

alpha=gdImageColorAllocateAlpha(bpp8,127,127,127,0);

gdImageColorTransparent(bpp8,alpha);

gdImageFill(bpp8,0,0,alpha);


//copy bpp to  bpp8, set color reduce method and speed and reduce color to 8 bit

gdImageCopy(bpp8,bpp,0,0,0,0,mWidth,mHeight);

gdImageTrueColorToPaletteSetMethod(bpp8,10,3);

gdImageTrueColorToPalette(bpp8,1,256);


//save png into a buffer in memory

pTempPngbuffer=(unsigned char *)gdImagePngPtr(bpp8,&iSize);

你可能感兴趣的:(图像压缩,c/c++)