Home > Software engineering >  Consult if transparent PNG file is generated by Cimage?
Consult if transparent PNG file is generated by Cimage?

Time:10-02

Cstrings fnBmp="E: \ \ Projects \ \ x.b mp";
CImage im;
Im. The Load (fnBmp);
Cstrings mypng="E: \ \ Projects \ \ x.p ng";
//what kind of code added in this time?
Im. Save (mypng Gdiplus: : ImageFormatPNG);

Thank you very much

CodePudding user response:

This code is not already complete? Are there any questions?

CodePudding user response:

reference 1st floor zgl7903 response:
this code is not already complete? Are there any questions?

Need a transparent PNG
Looking for a period of
Void CrossImage (CImage & amp; Img)//to pixel transform
{
for(int i=0; i{
For (int j=0; J{
UCHAR * cr=(UCHAR *) img. GetPixelAddress (I, j);
Cr [0]=cr cr [3] [0] */255;
Cr [1]=cr * cr [1] [3]/255;
Cr [2]=cr * cr [2] [3]/255;
}
}
}

Cstrings fnBmp="E: \ \ Projects \ \ x.b mp";
CImage im;
Im. The Load (fnBmp);
CrossImage (im);//add the
Im. Save (mypng Gdiplus: : ImageFormatPNG);

This should be transparent

CodePudding user response:

Transparent and opaque can view the image attributes, believe that the information in the bit depth, if is 32 is a channel of figure, the conversion, you didn't see have what special treatment

CodePudding user response:

 
Void AlphaBmp ()
{
Bitmap OldBmp (L "red24. BMP");
Int. W=OldBmp GetWidth ();
If (w==0) return;
Int h=OldBmp. GetHeight ();
If (h==0) return;
//
Bitmap newBmp (w, h, PixelFormat32bppPARGB);

for(int i=0; i{
BYTE a=128;//cr. GetA ();
Color cr;
For (int j=0; J{
OldBmp. GetPixel (j, I, & amp; Cr);
NewBmp. SetPixel (j, I, Color (a, cr. GetR (), cr. GetG (), cr, GetB ()));
}
}
//
Clsids clsids;
GetEncoderClsid (L "image/PNG", & amp; Clsids);
WCHAR fileName [60]=L "HalfRed. PNG";
//
NewBmp. Save (fileName, & amp; Clsids);
AfxMessageBox (" HalfRed PNG Saved!" );
}


Use GDI +
24 bits BMP to 32 bit PNG

CodePudding user response:

reference 4 floor schlafenhamster response:
 
Void AlphaBmp ()
{
Bitmap OldBmp (L "red24. BMP");
Int. W=OldBmp GetWidth ();
If (w==0) return;
Int h=OldBmp. GetHeight ();
If (h==0) return;
//
Bitmap newBmp (w, h, PixelFormat32bppPARGB);

for(int i=0; i{
BYTE a=128;//cr. GetA ();
Color cr;
For (int j=0; J{
OldBmp. GetPixel (j, I, & amp; Cr);
NewBmp. SetPixel (j, I, Color (a, cr. GetR (), cr. GetG (), cr, GetB ()));
}
}
//
Clsids clsids;
GetEncoderClsid (L "image/PNG", & amp; Clsids);
WCHAR fileName [60]=L "HalfRed. PNG";
//
NewBmp. Save (fileName, & amp; Clsids);
AfxMessageBox (" HalfRed PNG Saved!" );
}


Use GDI +
24 bits BMP to 32 bit PNG

Per-pixel whole is low efficiency,

CodePudding user response:

Related to the number of each like alpha, if is a BYTE a=128; Should hurry up

CodePudding user response:

Each point alpha is different:
 
for(int i=0; i{
BYTE a;//=128;//cr. GetA ();
Color cr;
For (int j=0; J{
OldBmp. GetPixel (j, I, & amp; Cr);
COLORREF which=cr. ToCOLORREF ();
If (which==RGB (255255255)) a=0;//0 means completely transparent
Else a=128;//255 said opaque
NewBmp. SetPixel (j, I, Color (a, cr. GetR (), cr. GetG (), cr, GetB ()));
}
}
  • Related