screenshot-rs icon indicating copy to clipboard operation
screenshot-rs copied to clipboard

screenshot on windows

Open lynnux opened this issue 6 years ago • 1 comments

I have implement screenshot in C, and I found a way not need flip_rows on windows.

BITMAPINFOHEADER bih = {0};
    bih.biBitCount = bmp.bmBitsPixel;
    bih.biCompression = BI_RGB;
    bih.biHeight = - bmp.bmHeight;   // set this to negative

and there need to convert bgra to rgba

unsigned char* bgra2rgba(unsigned char* buf, DWORD size)
{
    if(0 == size % 4)
    {
        unsigned char* ret = new unsigned char[size]; // new alloc is only need for my own project
        memcpy(ret, buf, size);
        DWORD all_chunks = size / 4;
        for(DWORD i = 0; i< all_chunks; ++i)
        {
            ret[i*4+2] = buf[i*4]; // swap b, r
            ret[i*4] = buf[i*4+2];
            ret[i*4+3] = 255; // alpha channel: XP need this
        }
        return ret;
    }
    return 0;
}

lynnux avatar Sep 18 '17 02:09 lynnux