A little module: AlphaBlt() and AlphaBlend() functions will let you render 32-bit-alpha bitmaps onto a given DC. Use first one (faster) when rendering onto solid-color surfaces. Use second one for a complete emulation of API's AlphaBlend. // W9x and WNT systems compatible, I hope. // ~115Kb. __________________________________________________
Update #1. Added cDIB32 class (simplified version accepting only 32-bit DIB sections). Useful in case loading a resource bitmap. All properties have been preserved to allow create/edit custom alpha DIBs. Thanks go to redbird77 for the new CreateFromResourceBitmap() function. Note: compile first if you want to test this function! (also you'll get about 10 times faster results).
Update #2. Added a mini-tool to export 32-bit bitmaps from icon/cursor resources (XP format). __________________________________________________ Update #3 (2005.05.03). Speed up: checked special alpha values (full opaque and full transparent).
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come
out every day, so no prevention program can catch 100% of them. For your own safety, please:
Re-scan downloaded files using your personal virus checker before using it.
NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Scan the source code with Minnow's Project Scanner
If you don't have a virus scanner, you can get one at many places on the net
Terms of Agreement:
By using this code, you agree to the following terms...
You may use
this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this code from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
In fact, both functions should also check for alpha channel. We could be in front of a true-color bitmap stored as a 32-bit one without alpha information. In that case, we will see 'nothing' :-) So it's supposed user knows what is loading. (If this comment was disrespectful, please report it.)
(If this comment was disrespectful, please report it.)
4/2/2005 5:54:18 AM:
Wooooooowwwww!!!!! Nothing less then WoW! Nice code Carles! 5***** from me again! U know, this code would be complete if you add a little thing in your function like, giving the height and width of the image, so the picture is fully resizable when painting. Hope to see this in it too. My God this code is great! Keep up the good work! Thanx! (If this comment was disrespectful, please report it.)
4/2/2005 6:31:36 AM:
Is it posible to add picture from resource? Thx! (If this comment was disrespectful, please report it.)
Resizing: Not so 'straight-forward'. This would need pre-processing scaled bitmap with respective destination area. Taking in account we are rendering alpha-bitmaps ('soft-edged'), it should be 'necessary' to interpolate (both color and alpha channels) to get a 'correct' result. This would take a 'litte bit more' of processing time. If someone wants to try it... :-) Anyway, a previous improvement could be let define source rectangle area (always at 1:1). This could be useful for 'clipping' purposes (BeginPaint-EndPaint -> update region, etc). (If this comment was disrespectful, please report it.)
4/2/2005 11:34:14 PM:
Flawless; well done! (If this comment was disrespectful, please report it.)
Great Code man, but some how the result is much slowr in my PC, my CPU is AMD Athlon 64 +3700 2.17 GHZ... and i use XP.... ? any one knows why? Great Code.. i vote ***** globes... (If this comment was disrespectful, please report it.)
Hi Carles, I am having trouble painting translucent bitmap directly to screen, (for form skinner), bg is always black, if you have any ideas, can you email me? (If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular code, please
click here instead.)