c++ - MFC displaying png with transparent background -
i need way display png image transparent background on background gradient color.
i have tried this:
cimage img; cbitmap bmp; img.load(_t(".\\res\\foo.png")); bmp.attach(img.detach()); cdc dcstatus; dcstatus.createcompatibledc(&dc); dcstatus.selectobject(&bmp); dcstatus.setbkcolor(transparent); dc.bitblt(recttext.left + 250, recttext.top, 14, 14, &dcstatus, 0, 0, srccopy); bmp.deleteobject();
but foo.png gets black background wherever transparent in original image.
i did seek new bitmap painted transparent color , did possible operations on it, didn't help. sample of 1 permutation:
cimage img; cbitmap bmp; img.load(_t(".\\res\\foo.png")); bmp.attach(img.detach()); cbitmap bmpmaska; bmpmaska.createbitmap(14, 14, 1, 1, null); cdc dcstatus; dcstatus.createcompatibledc(&dc); dcstatus.selectobject(&bmp); cdc dcmaska; dcmaska.createcompatibledc(&dc); dcmaska.selectobject(&bmpmaska); dcmaska.setbkcolor(dcstatus.getpixel(0, 0)); //todo: bitmap ni transparent dc.bitblt(recttext.left + 250, recttext.top, 14, 14, &dcmaska, 0, 0, srccopy); dc.bitblt(recttext.left + 250, recttext.top, 14, 14, &dcstatus, 0, 0, srcand); bmp.deleteobject(); bmpmaska.deleteobject();
this did not trick. either, there black square on screen, or result same original.
i have checked alphablend api, code must pure mfc + c++ witthout additional apis. [edit]: company policy little apis possible. code supposed run on embedded windows systems in real time.
[edit 2]: not bound png image format, meaning, display transparent, goes.
please, tell me doing wrong?
convert png 32 bit bmp file. google 'alphaconv' , utilize that. png's pita work - several api's claim back upwards them don't, or partially, or on platforms etc. load 32-bit bmp using cbitmap::loadbitmap (from resources - far easiest) then utilize cdc::alphablend() draw bitmap. transparentblt() doesn't work alpha channel - it's either draw pixel or not. alphablend part of win32 api, , still investigate cimage::alphablend if you'd like, has bug somewhere (i forgot exactly) utilize raw ::alphablend. but beware - need premultipy alpha channel right display. see reply on how draw 32-bit alpha channel bitmaps? .
no variation of described work. need api work. or, utilize getdibits , own version of ::alphablend() :)
c++ mfc png
No comments:
Post a Comment