本文介绍了如何混合两种RGBA颜色(像素)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好 我想混合两个32位位图,我在维基百科上找到了以下公式并创建了相应的代码,但效果不佳: 我的代码是: RGBQUAD * prgbaSrc =(RGBQUAD *)pSrcPixel; RGBQUAD * prgbaDest =(RGBQUAD *)pDestPixel; BYTE outAlpha = prgbaSrc-> rgbReserved + prgbaDest-> rgbReserved *(255 - prgbaSrc-> rgbReserved); if(outAlpha> 0) { prgbaDest-> rgbRed =(prgbaSrc-> rgbRed * prgbaSrc-> rgbReserved / 255 + prgbaDest-> rgbRed * prgbaDest-> rgbReserved / 255 *(255 - prgbaSrc-> rgbReserved)/ 255)/ outAlpha; prgbaDest-> rgbGreen =(prgbaSrc-> rgbGreen * prgbaSrc-> rgbReserved / 255 + prgbaDest-> rgbGreen * prgbaDest-> rgbReserved / 255 *(255 - prgbaSrc-> rgbReserved)/ 255 )/ outAlpha; prgbaDest-> rgbBlue =(prgbaSrc-> rgbBlue * prgbaSrc-> rgbReserved / 255 + prgbaDest-> rgbBlue * prgbaDest-> rgbReserved / 255 *(255 - prgbaSrc-> rgbReserved)/ 255 )/ outAlpha; } 其他 { prgbaDest-> rgbRed = 0; prgbaDest-> rgbGreen = 0; prgbaDest-> rgbBlue = 0; } prgbaDest-> rgbReserved = outAlpha; 解决方案 公式假定alpha值归一化为[0.0,1.0]范围。你没有为[0,255]范围正确调整它们 - 你的因子是255.使它 BYTE outAlpha = prgbaSrc-> rgbReserved + prgbaDest-> rgbReserved *(255 - prgbaSrc-> rgbReserved)/ 255; 这里也是,但是在另一个方向。设为 prgbaDest-> rgbRed =(prgbaSrc-> rgbRed * prgbaSrc-> ; rgbReserved + prgbaDest-> rgbRed * prgbaDest-> rgbReserved *(255 - prgbaSrc-> rgbReserved)/ 255)/ outAlpha; HiI want to blend two 32bit bitmaps, I found following formula on Wikipedia and create a corresponding code but not good result:My code is:RGBQUAD* prgbaSrc = (RGBQUAD*)pSrcPixel;RGBQUAD* prgbaDest = (RGBQUAD*)pDestPixel;BYTE outAlpha = prgbaSrc->rgbReserved + prgbaDest->rgbReserved * (255 - prgbaSrc->rgbReserved);if (outAlpha > 0){prgbaDest->rgbRed = (prgbaSrc->rgbRed * prgbaSrc->rgbReserved / 255 + prgbaDest->rgbRed * prgbaDest->rgbReserved / 255 * (255 - prgbaSrc->rgbReserved) / 255) / outAlpha;prgbaDest->rgbGreen = (prgbaSrc->rgbGreen * prgbaSrc->rgbReserved / 255 + prgbaDest->rgbGreen * prgbaDest->rgbReserved / 255 * (255 - prgbaSrc->rgbReserved) / 255) / outAlpha;prgbaDest->rgbBlue = (prgbaSrc->rgbBlue * prgbaSrc->rgbReserved / 255 + prgbaDest->rgbBlue * prgbaDest->rgbReserved / 255 * (255 - prgbaSrc->rgbReserved) / 255) / outAlpha;}else{prgbaDest->rgbRed = 0;prgbaDest->rgbGreen = 0;prgbaDest->rgbBlue = 0;}prgbaDest->rgbReserved = outAlpha; 解决方案 The formula assumes that alpha values are normalized to [0.0, 1.0] range. You didn't adjust them correctly for [0, 255] range - you are off by a factor of 255. Make itBYTE outAlpha = prgbaSrc->rgbReserved + prgbaDest->rgbReserved * (255 -prgbaSrc->rgbReserved) / 255;And here too, but in the other direction. Make itprgbaDest->rgbRed = (prgbaSrc->rgbRed * prgbaSrc->rgbReserved +prgbaDest->rgbRed * prgbaDest->rgbReserved * (255 -prgbaSrc->rgbReserved) / 255) / outAlpha; 这篇关于如何混合两种RGBA颜色(像素)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-18 00:52