1//1. Unit Contents 2 Unit Unitalienform; 3 Interface 4 uses 5 Windows, Forms, Classes, Graphics; 6//Load PNG 7 procedure alienform_pngfromfile from file (aform:tform; afilename:string); 8//Load PNG 9 procedure Alienform_pngfromresource from resource (aform:tform; resname:string; Restype:pwidechar; Instance:hinst = 0); 10//Load from image object One by one procedure alienform_pngfromgraphic (aform:tform; agraphic:tgraphic); Implementation13 procedure Alienform_pngfromfile (aform:tform; afilename:string); Var15 wic:twicimage;16 begin17 WIC: = twicimage.create;18 WIC. LoadFromFile (Afilename), Alienform_pngfromgraphic (Aform, WIC), WIC. Free;21 end;22 procedure Alienform_pngfromresource (aform:tform; resname:string; Restype:pwidechar; Instance:hinst); Var24 wic:twicimage;25 r:tresourcestream;26 begin27 If Instance = 0 then28 Instance: = hinstance;29 r: = Tresourcestream.create (Instance, Resname, ResType); WIC: = twicimage.create;31 WIC. Loadfromstream (r); alienform_pngfromgrAphic (Aform, WIC); free;34 r.free;35 end;36 procedure alienform_pngfromgraphic (aform:tform; agraphic:tgraphic); var38 ptdst, ptsrc:tpoint;39 size:tsize;40 blendfunction:tblendfunction;41 Bmp:tbitma p;42 begin43 BMP: = tbitmap.create;44 bmp. Assign (agraphic); PTDST: = Point (Aform.left, aform.top); PTSRC: = Point (0, 0); Size.cx: = agraphic.width;48 Size.cy: = agraphic.height;49 Blendfunction.blendop: = ac_src_over;50 blendfunction.blendflags: = 0;51 BlendFunction . Sourceconstantalpha: = $FF; Transparency Blendfunction.alphaformat: = ac_src_alpha;53 SetWindowLong (aform.handle, Gwl_exstyle, GetWindowLong (AForm.Ha ndle,54 gwl_exstyle) or ws_ex_layered) Updatelayeredwindow (aform.handle,56 aform.canvas.handle,57 @pt dst,58 @Size, BMP. canvas.handle,60 @ptSrc, 0,62 @BlendFunction, Ulw_alpha), BMP. Free (); end;66 end.67 68//2. Calling method procedure Tform2.formcreate (Sender:tobject);1 alienform_pngfromfile (Form2, ' e:\ untitled. png ');
Http://www.cnblogs.com/FKdelphi/p/5843038.html
Delphi Special Window png