문제

I recently found this (Win32 API Speed Issues) to improve drawing speed, but it seems the code :

pBits[(y * WIDTH) + x] = RGB(0, 0, 0xFF);

always make the image flipped (from bottom-left to top-right),

Do you guys know how to fix this problem ??

.

Here's the flipped image:

flipped-bitmap.png

Here's my code :

for (i=0; i<200; i++) {
    for (j=0; j<200; j++) {
        int x, y;
        cr1 = GetPixel(hdc_tmp, i*2, j*2);
        cr2 = GetPixel(hdc_tmp, i*2, 1+j*2);
        cr3 = GetPixel(hdc_tmp, 1+i*2, j*2);
        cr4 = GetPixel(hdc_tmp, 1+i*2, 1+j*2);

        red = (GetRValue(cr1) + GetRValue(cr2) + GetRValue(cr3) + GetRValue(cr4)) / 4;
        green = (GetGValue(cr1) + GetGValue(cr2) + GetGValue(cr3) + GetGValue(cr4)) / 4;
        blue = (GetBValue(cr1) + GetBValue(cr2) + GetBValue(cr3) + GetBValue(cr4)) / 4;

        pbits[i+j*200] = RGB(red, green, blue); // BUG ??
    }
}

BitBlt(hdc, 0, 0, 200, 200, hdc_aa, 0, 0, SRCCOPY);
도움이 되었습니까?

해결책

It's common for a DIB section to be held in memory from the bottom scanline up.

You can either adjust your pBits index to write from the bottom row first, or change the sign of the height on the BITMAPINFOHEADER that describes the DIB section.

For example:

bmp.bmiHeader.biHeight = -HEIGHT;

The sign of the height determines whether or not the DIB section is treated as bottom-up or top-down.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top