Create CImage from Byte array

后端 未结 4 780
面向向阳花
面向向阳花 2020-12-21 12:02

I need to create a CImage from a byte array (actually, its an array of unsigned char, but I can cast to whatever form is necessary). The byte array is in the fo

4条回答
  •  天命终不由人
    2020-12-21 12:30

    CImage supports DIBs quite neatly and has a SetPixel() method so you could presumably do something like this (uncompiled, untested code ahead!):

    CImage img;
    img.Create(width, height, 24 /* bpp */, 0 /* No alpha channel */);
    
    int nPixel = 0;
    for(int row = 0; row < height; row++)
    {
        for(int col = 0; col < width; col++)
        {
            BYTE r = imgBits[nPixel++];
            BYTE g = imgBits[nPixel++];
            BYTE b = imgBits[nPixel++];
            img.SetPixel(row, col, RGB(r, g, b));
        }
    }
    

    Maybe not the most efficient method but I should think it is the simplest approach.

提交回复
热议问题