Windows API function (5) in VCL: alphablend

Source: Internet
Author: User
Alphablend is a function used to specify image transparency. It is used in graphics, graphutil, and ribbonstyleactnctrls.

In the following test, an image is displayed in the form and the transparency can be adjusted.

In this example:


Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, comctrls; Type tform1 = Class (tform) trackbar1: ttrackbar; procedure outputs (Sender: tobject); Procedure formdestroy (Sender: tobject); Procedure trackbar1change (Sender: tobject); Procedure outputs (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} var bit: tbitmap; Procedure tform1.formcreate (Sender: tobject); begin bit: = tbitmap. create; bit. loadfromfile ('C: \ temp \ test.bmp '); trackbar1.min: = 0; trackbar1.max: = 255; trackbar1.position: = 128; doublebuffered: = true; end; Procedure tform1.formdestroy (Sender: tobject); begin bit. free; end; Procedure tform1.formpaint (Sender: tobject); var blendfunc: tblendfunction; begin blendfunc. blendop: = ac_src_over; blendfunc. blendflags: = 0; blendfunc. sourceconstantalpha: = trackbar1.position; If bit. pixelformat = pf32bit then blendfunc. alphaformat: = ac_src_alpha else blendfunc. alphaformat: = 0; windows. alphablend (canvas. handle, {Target DC} 30, 10, bit. width, bit. height, {target location and size} bit. canvas. handle, {source DC} 0, 0, bit. width, bit. height, {source location and size} blendfunc {transparent structure}); end; Procedure tform1.trackbar1change (Sender: tobject); begin repaint; end.
 
   
 

Form file:

 
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 206 clientwidth = 223 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false oncreate = formcreate ondestroy = formdestroy onpaint = formpaint pixelsperinch = 96 textheight = 13 object trackbar1: ttrackbar left = 8 Top = 175 width = 207 Height = 23 showselrange = false taborder = 0 onchange = trackbar1change endend

  
Related Article

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.