Transparent PNG picture display issues about CImage and AlphaBlend

Source: Internet
Author: User

PNG picture transparent background is always a white, only later found that this is actually Microsoft GDI + design problem, png picture is ARGB, use GDI + load the picture, GDI + will default has been the pre-residual operation (PARGB), That is, the actual value of each pixel is already proportional to the alpha value of the result, in fact it does not do a prefetch, in the use of transparent image of the Pixel alpha channel, CImage inside is the call of the AlphaBlend, The result of a picture that does not have a pre-multiplication as a pre-multiply image is that this is the equivalent of a single and white background, so the image always appears as a white background.

The final solution, write a small program to the PNG image of each pixel for the operation, and then save the PNG picture, the actual effect is good.

I overwrote cimage::load () and now everything works fine:


HRESULT cimg::load (LPCTSTR pszfilename, bool bpremultiply)
{
 hresult retres = Cimage::load ( pszFileName);
 if (! IsNull () && bpremultiply)
 {
  unsigned char * pcol = 0;
  long LW = getwidth ();
  long LH = GetHeight ();
  for (Long ixy = 0; Ixy < LH; Ixy + +)
  {
   for (Long Ixx = 0; Ixx < LW ; Ixx + +)
   {
    pcol = (unsigned char *) getpixeladdress (IXX,IXY);
    unsigned char alpha = pcol[3];
    if (Alpha < 255)
    {
    pcol[0] = ( (pcol[0] * Alpha) + 127)/255;
    pcol[1] = ((pcol[1] * Alpha) + 127)/255;
    pcol[2] = ((pcol[2] * Alpha) + 127)/255;
    }
   }
  }
 }
 return retres;
}

PS: Finally found that there are some PNG map of the transparent color can be processed properly, and now suspect that these pictures are not exported the way the resulting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.