Important alert: (current site time 7/16/2013 2:45:44 AM EDT)
 

winzip icon

API's AlphaBlend emulation

Email
Submitted on: 4/1/2005 6:04:23 PM
By: Carles P.V. 
Level: Intermediate
User Rating: By 29 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 23507
 
     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).

 
winzip iconDownload code

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:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. 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 including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. 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.
  2. 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.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 53 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/1/2005 6:40:02 PMCarles P.V.


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.)

 
4/1/2005 8:36:06 PMZhu JinYong

Zip file missed cTile.cls;
and:
'Call AlphaBlt(Me.hDC, i * 32 - 10, j * 32 - 10, Me.BackColor, hBitmap)
Call AlphaBlend(Me.hDC, i * 32 - 10, j * 32 - 10, hBitmap)
(If this comment was disrespectful, please report it.)

 
4/1/2005 10:22:43 PMCarles P.V.

Sorry, updated.
(If this comment was disrespectful, please report it.)

 
4/2/2005 3:07:44 AMLight Templer

Carles, this rocks! Clean code working like a charm! Supporting ALL Windows versions is very noble! My *****+ for! ;)
Regards - LiTe
(If this comment was disrespectful, please report it.)

 
4/2/2005 5:05:28 AMPhantom Man

Well Done Carles.
5* Submission

Regards
Gary


(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.)

 
4/2/2005 9:02:51 AMJim K

Very nice CPV.

ÕÕÕÕÕ


(If this comment was disrespectful, please report it.)

 
4/2/2005 11:48:37 AMVlad Vissoultchev

Has troubles in 256-color modes. Works on NT.

cheers,
</wqw>
(If this comment was disrespectful, please report it.)

 
4/2/2005 3:07:32 PMFunny Dog

This is brilliant.

You being the grahics guru, how about making a custom imagelist that supports your dropshadow and 32 bit icons and doesn't need to depend on the hefty comctl32.dll.

Works fine on win98.
(If this comment was disrespectful, please report it.)

 
4/2/2005 6:02:25 PM

How can we change the size of the picture when painting? Does it support this yet? Thx
(If this comment was disrespectful, please report it.)

 
4/2/2005 6:54:05 PMCarles P.V.

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.)

 
4/4/2005 12:54:53 PMenmity

Hey, another exceptional code!
(If this comment was disrespectful, please report it.)

 
4/4/2005 3:52:02 PMAbhishek.NET

i think u sould make a paint shop pro or a icon editor using your graphics skills!
(If this comment was disrespectful, please report it.)

 
4/14/2005 9:46:59 PM

Well Done Buddy. 5 Star
(If this comment was disrespectful, please report it.)

 
4/15/2005 5:29:52 PMFred.cpp

He already did a Icon Editor (the one I use). Excellent as usual, 5 globes.
(If this comment was disrespectful, please report it.)

 
5/4/2005 7:03:05 AMHardStream Software Development

Really great code... 5x* from me :D
(If this comment was disrespectful, please report it.)

 
7/8/2005 4:46:55 PMHardStream Software Development

Btw. I'm using your code for my shell (if it's ok with you of course)... That way I'll be able to display the 32 bit icons of files and applications :D

Tnx again
(If this comment was disrespectful, please report it.)

 
11/12/2005 9:58:17 PMYozz

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.)

 
3/9/2006 3:54:31 PMSteppenwolfe

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.)
 

To post feedback, first please login.