GetPixelAddress()函数Alpha通道会丢失
CImage类中GetPixelAddress()函数来设置获取对应的颜色值是发现Alpha无效。
- void CGBImage::Load(){
- CImage sourceImage;
- sourceImage.Load(L"C:\\Users\\Ju\'k\\Desktop\\CGaussBlur\\1.png");
- int bpp = sourceImage.GetBPP();
- int width = sourceImage.GetWidth();
- int height = sourceImage.GetHeight();
- CImage newImage;
- newImage.Create(width,height,32);
- for(int w = 0; w < width;w++){
- for(int h = 0; h < height;h++){
- if(w == 20 && h == 20){
- int xx = 0;
- }
- BYTE* buffer = (BYTE*)sourceImage.GetPixelAddress(w,h);
- BYTE b = buffer[0];
- BYTE g = buffer[1];
- BYTE r = buffer[2];
- BYTE a = buffer[3];
- BYTE* newBuffer = (BYTE*)newImage.GetPixelAddress(w,h);
- newBuffer[0] = b;
- newBuffer[1] = g;
- newBuffer[2] = r;
- newBuffer[3] = a;
- }
- }
- CLSID pngClsid;
- GetEncoderClsid(_T("image/png"), &pngClsid);
- newImage.Save(L"C:\\Users\\Ju\'k\\Desktop\\CGaussBlur\\1_1.png");
- }
不管 newBuffer[3] = a; 如何设置 newImage始终无法透明。
这里要注意的是
newImage.Create(width,height,32);
这里第三个函数一定要设置为32
第四个函数这里是默认的为0,应该设置为CImage::createAlphaChannel。