任何将8bpp bitmap
转换为32bpp bitmap
的方法,基本上我想将单色bitmap
转换为颜色bitmap
,单色bitmap
拥有{{1} }我想将其带入8bpp
,Google中的大多数问题是从上到下的转换。
答案 0 :(得分:2)
8bpp通常表示您有一个颜色图,并且像素颜色值是该颜色图的索引。
32bpp通常是RGBA或ARGB,具有单独的红色,绿色和蓝色(和Alpha)成分。
要将索引的颜色表图像转换为RGB图像,只需将8bpp图像中的所有像素替换为颜色表中的相应RGB值即可。
响应Mark Setchell的评论,处理8位灰度值几乎更为简单:从原始图像中获取像素值,并将其用于所有R,G和B。
例如如果原始像素值为0x37
,则R,G和B中的每一个也将变为0x37
(即,对于ARGB,0x00373737
和对于RGBA,0x37373700
)。
答案 1 :(得分:2)
这是一些基于Mark Setchell的注释的代码(“ P,P,P + 255 ”)。 (这是未经测试的,很抱歉-我可能会有一些“一一失误”的错误,但我只想让您了解它的外观):
/// NB this will allocate memory, where you put the
/// malloc depends on your context. But you do need one somewhere.
/// pImgOut is the resulting 32 bits-per-pixel image.
/// width and height are the width and height of original 8bit pixmap.
void make8bppTo32bpp(uint8_t* pPixmapIn, uint8_t** pImgOut, int width, int height)
{
*pImgOut = (uint8_t*)malloc((width*height)*4); //32 bits per pixel == 4 bytes per pixel
uint8_t* pSrc = pPixmapIn;
uint8_t* pDst = *pImgOut;
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
// assign R,G,B of dest all to be the same cur pix val of src.
uint8_t pixval = *pSrc;
*pDst++ = pixval;
*pDst++ = pixval;
*pDst++ = pixval;
*pDst++ = 255; // make alpha channel fully opaque
// next src pixel
pSrc++;
}
}
}