Fromhbitmap This function will lose transparency information.

Source: Internet
Author: User

In the use of fromhbitmap you will find out the figure is with black edge, this is because this function has a bug, the solution is to use the following function to convert, the general meaning is that you memcpy do not use Fromhbitmap function.

 bitmap* Createbitmapfromhbitmap (in Hbitmap hbitmap) {Bitmap bmp = {0};        if (0 = = GetObject (hbitmap, sizeof (BITMAP), (LPVOID) &bmp)) {return FALSE;        } BYTE *piexlssrc = NULL;        LONG cbsize = bmp.bmwidthbytes * bmp.bmheight;        PIEXLSSRC = new Byte[cbsize];        Bitmapinfo Bmpinfo = {0};        bmpInfo.bmiHeader.biSize = sizeof (Bitmapinfoheader);        BmpInfo.bmiHeader.biWidth = Bmp.bmwidth;         BmpInfo.bmiHeader.biHeight = Bmp.bmheight;        BmpInfo.bmiHeader.biPlanes = Bmp.bmplanes;        BmpInfo.bmiHeader.biBitCount = Bmp.bmbitspixel;        BmpInfo.bmiHeader.biCompression = Bi_rgb;        HDC hdcscreen = CreateDC (L "DISPLAY", NULL, Null,null);        LONG cbcopied = GetDIBits (hdcscreen, hbitmap, 0, Bmp.bmheight, PIEXLSSRC, &bmpinfo, dib_rgb_colors);        DeleteDC (Hdcscreen);            if (0 = = cbcopied) {delete [] piexlssrc;        return FALSE; } Bitmap *pbitmap = new Bitmap (Bmp.bmwidth, Bmp.bmheight, Pixelformat32bpppargb);        BitmapData BitmapData;        Rect rect (0, 0, bmp.bmwidth, bmp.bmheight);        if (Ok! = Pbitmap->lockbits (&rect, Imagelockmoderead, Pixelformat32bpppargb, &bitmapdata))            {Safe_delete (PBITMAP);        return NULL;        } BYTE *pixelsdest = (byte*) bitmapdata.scan0;        int nlinesize = bmp.bmwidth * sizeof (UINT);        int nheight = Bmp.bmheight;                 for (int y = 0; y < nheight; y++) {memcpy_s (pixelsdest + y * nlinesize), nlinesize,        (Piexlssrc + (NHEIGHT-Y-1) * nlinesize), nlinesize);        } if (Ok! = pbitmap->unlockbits (&bitmapdata)) {delete pbitmap;        } delete [] piexlssrc;    return pbitmap; }

  

Reference information: http://blog.sina.com.cn/s/blog_5f8817250100g1dj.html

Https://groups.google.com/forum/#!topic/microsoft.public.win32.programmer.gdi/stjG06_EPfM

Fromhbitmap This function will lose transparency information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.