hbitmap

C++/Win32: How to get the alpha channel from an HBITMAP?

人走茶凉 提交于 2019-11-30 19:06:23
I have an HBITMAP containing alpha channel data. I can successfully render this using the ::AlphaBlend GDI function. However, when I call the ::GetPixel GDI function, I never get back values with an alpha component. The documentation does say that it returns the RGB value of the pixel. Is there a way to retrieve the alpha channel values for pixels in an HBITMAP ? I want to be able to detect when to use ::AlphaBlend, and when to use an old-school method for treating a particular colour in the source HBITMAP as transparent. HDC sourceHdc = ::CreateCompatibleDC(hdcDraw); ::SelectObject(sourceHdc,

Proper way close WinAPI HANDLEs (avoiding of repeated closing)

◇◆丶佛笑我妖孽 提交于 2019-11-30 05:38:18
问题 I have some handle and I need to close it. There is some places in code, where handle may be closed. So, is this a right way to close handle? HANDLE h; .... if ( h != INVALID_HANDLE_VALUE ) { ::CloseHandle(h); h = INVALID_HANDLE_VALUE; } There is a same question about bitmap handles: HBITMAP hb; .... if ( hb != INVALID_HANDLE_VALUE ) { ::DeleteObject(hb); hb = INVALID_HANDLE_VALUE; } EDIT: I think, there is some misunderstanding. I know CloseHandle is for closing handles. I'd like to know

Creating HBITMAP from memory buffer

僤鯓⒐⒋嵵緔 提交于 2019-11-27 05:34:38
I have an application which loads some blob data out of a database which can represent png formatted or raw binary data for various bitmaps and icons. This is being stored in a std::vector<unsigned char> I'm using CImageList objects to display various images in tree views, toolbar images, etc but the problem is creating bitmaps from the data in memory are coming out fuzzy as if it's missing pixels when doing something like below: std::vector<unsigned char> bits; HBITMAP hbitmap = CreateBitmap(16, 16, 1, 32, bits.data()); To work around this issue for now I am simply writing out the data() in

Save HBITMAP to *.bmp file using only Win32

前提是你 提交于 2019-11-27 04:17:21
I have a HBITMAP in my pure Win32 project (no external libraries are used). Can I export it to a *.bmp file using only Winapi and/or CRT functions so I don't incur any extra dependencies? Roman R. There is no API to save into file directly because, generally, having a bitmap handle does not mean you have direct access to bitmap data. Your solution is to copy bitmap into another bitmap with data access (DIB) and then using it data to write into file. You typically either create another bitmap using CreateDIBSection , or you get bitmap data with GetDIBits . CreateFile , WriteFile writes data

Use native HBitmap in C# while preserving alpha channel/transparency

淺唱寂寞╮ 提交于 2019-11-27 03:39:19
问题 Let's say I get a HBITMAP object/handle from a native Windows function. I can convert it to a managed bitmap using Bitmap.FromHbitmap(nativeHBitmap) , but if the native image has transparency information (alpha channel), it is lost by this conversion. There are a few questions on Stack Overflow regarding this issue. Using information from the first answer of this question (How to draw ARGB bitmap using GDI+?), I wrote a piece of code that I've tried and it works. It basically gets the native

Creating HBITMAP from memory buffer

ⅰ亾dé卋堺 提交于 2019-11-26 11:37:44
问题 I have an application which loads some blob data out of a database which can represent png formatted or raw binary data for various bitmaps and icons. This is being stored in a std::vector<unsigned char> I\'m using CImageList objects to display various images in tree views, toolbar images, etc but the problem is creating bitmaps from the data in memory are coming out fuzzy as if it\'s missing pixels when doing something like below: std::vector<unsigned char> bits; HBITMAP hbitmap =

Save HBITMAP to *.bmp file using only Win32

吃可爱长大的小学妹 提交于 2019-11-26 11:07:36
问题 I have a HBITMAP in my pure Win32 project (no external libraries are used). Can I export it to a *.bmp file using only Winapi and/or CRT functions so I don\'t incur any extra dependencies? 回答1: There is no API to save into file directly because, generally, having a bitmap handle does not mean you have direct access to bitmap data. Your solution is to copy bitmap into another bitmap with data access (DIB) and then using it data to write into file. You typically either create another bitmap