cpp
复制代码
CImage img;
#include <webp/decode.h>
#include <fstream>
#include <wingdi.h>
void parse(CDC* dc)
{
std::ifstream ifs("None-1.webp", std::ios::binary);
ifs.seekg(0, std::ios::end);
auto size = ifs.tellg();
ifs.seekg(0, std::ios::beg);
std::vector<uint8_t> data(size);
ifs.read((char*)data.data(), data.size());
ifs.close();
int width = 0;
int height = 0;
auto ret = WebPGetInfo(data.data(), size, &width, &height);
//WebPDecoderConfig config;
#if 0
auto webpdata = WebPDecodeRGBA(data.data(), size, &width, &height);
for (int of = 0, max = width * height * 4; of < max; of += 4) {
auto b = webpdata[of + 0];
auto g = webpdata[of + 1];
auto r = webpdata[of + 2];
webpdata[of + 0] = r;
webpdata[of + 1] = g;
webpdata[of + 2] = b;
//webpdata[of+0] = 255; // blue
//webpdata[of+1] = 255; // green
//webpdata[of+2] = 255; // red
webpdata[of+3] = 0;
}
#else
auto webpdata = WebPDecodeBGRA(data.data(), size, &width, &height);
#endif
std::cout << "width: " << width << ", height: " << height << std::endl;
uint32_t nPlanes = 1;
uint32_t nBitCount = 4 * 8;
auto cj = (((width * nPlanes * nBitCount + 15) >> 4) << 1) * height;
std::cout << "buffer size: " << cj << std::endl;
auto hbitmap = CreateBitmap(width, height, nPlanes, nBitCount, webpdata);
//uint32_t errno_ = ERROR_INVALID_BITMAP;
std::cout << "create bitmap: " << hbitmap << std::endl;
CDC memDC; //定义一个显示设备对象
memDC.CreateCompatibleDC(dc); //创建CDC兼容设备
memDC.SetBkMode(TRANSPARENT);
memDC.SelectObject(hbitmap); //设备选择当前的图纸-位图
DeleteObject(hbitmap);
dc->SetStretchBltMode(STRETCH_HALFTONE);
dc->StretchBlt(100, 100, 100, 100, &memDC, 0, 0, width, height, SRCAND);
//dc->BitBlt(100, 100, width, height, &memDC, 0, 0, SRCAND);
//dc->TransparentBlt(100, 100, width, height, &memDC, 0, 0, width, height, 0x00ffff00);
}