sammycage / lunasvg

SVG rendering and manipulation library in C++
MIT License
866 stars 124 forks source link

Bitmap compatibility #7

Closed spger closed 4 years ago

spger commented 4 years ago

Hi, I will like to know if is possible or there is some kind of compatibility to cast lunasvg::Bitmap to CBitmap. Regards

sammycage commented 4 years ago
    // rgba to bgra
    std::uint8_t* ptr = bitmap.data();
    std::uint8_t* end = bitmap.data() + bitmap.height() * bitmap.stride();
    while(ptr < end)
    {
        std::uint8_t r = ptr[0];
        std::uint8_t g = ptr[1];
        std::uint8_t b = ptr[2];
        std::uint8_t a = ptr[3];

        ptr[0] = b;
        ptr[1] = g;
        ptr[2] = r;
        ptr[3] = a;

        ptr += 4;
    }

    HBITMAP handle = CreateBitmap(bitmap.width(), bitmap.height(), 1, 32, bimap.data());
    CBitmap cbimap = CBitmap::FromHandle(handle);

If it works lemme know.

spger commented 4 years ago

Its working! Thank you