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) ;
# if 0 auto webp data = WebPDecodeRGBA ( data. data ( ) , size, & width, & height) ; for ( int of = 0 , max = width * height * 4 ; of < max; of += 4 ) { auto b = webp data[ of + 0 ] ; auto g = webp data[ of + 1 ] ; auto r = webp data[ of + 2 ] ; webp data[ of + 0 ] = r; webp data[ of + 1 ] = g; webp data[ of + 2 ] = b; webp data[ of+ 3 ] = 0 ; }
# else auto webp data = 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, webp data) ; std:: cout << "create bitmap: " << hbitmap << std:: endl; CDC memDC; memDC. CreateCompatibleDC ( dc) ; memDC. SetBkMode ( TRANSPARENT) ; memDC. SelectObject ( hbitmap) ; DeleteObject ( hbitmap) ; dc-> SetStretchBltMode ( STRETCH_HALFTONE) ; dc-> StretchBlt ( 100 , 100 , 100 , 100 , & memDC, 0 , 0 , width, height, SRCAND) ;
}