Where is the problem in my code for generating a bitmap from a byte array?

55 views Asked by At

i create bitmap from that byte array, and setBitmap on my picture control However, no image is displayed. Where is the problem in my code for generating a bitmap from a byte array?

[OnInitDialog]

PICTURE_MY.GetWindowRect(&rect); //PICTURE_MY is my picture control
MAX_CANVAS_W = rect.right - rect.left;
MAX_CANVAS_H = rect.bottom - rect.top;
layerOne = new BYTE[3*((MAX_CANVAS_W-2)*(MAX_CANVAS_H-2))];
pitch = MAX_CANVAS_W - 2;

int count = 0;
while (count < 3 * ((MAX_CANVAS_W - 2) * (MAX_CANVAS_H - 2)))
{
    layerOne[count] = 255;
    count++;
}

[OnPaint]

HBITMAP h_bitmap = CreateBitmap(pitch, MAX_CANVAS_H - 2, 1, 24, layerOne);
CImage image;
image.Attach(h_bitmap);

PICTURE_MY.SetBitmap(image);

When I wrote the following code, it worked well, but it's too slow for my use case, and I don't want to use it

        CClientDC dc(this);
        for (int y = 0; y < MAX_CANVAS_H - 2; y++) 
        {
            for (int x = 0; x < pitch; x++) 
            {
                COLORREF color = RGB(layerOne[3*(y*pitch+x)], layerOne[3 * (y * pitch + x)+1], layerOne[3 * (y * pitch + x)+2]);
                dc.SetPixel(PICTURE_LEFTTOP.x+1 + x, PICTURE_LEFTTOP.y+y+1, color);
                
            }
        }
0

There are 0 answers