1 //1. Unit contents2 UnitUnitalienform;3 Interface4 uses5 Windows, Forms, Classes, Graphics;6 //load png from file7 procedureAlienform_pngfromfile (aform:tform; afilename:string);8 //To load a PNG from a resource9 procedureAlienform_pngfromresource (Aform:tform; resname:string; Restype:pwidechar; Instance:hinst =0);Ten //loading from an Image object One procedurealienform_pngfromgraphic (aform:tform; agraphic:tgraphic); A Implementation - procedureAlienform_pngfromfile (aform:tform; afilename:string); - var the Wic:twicimage; - begin -WIC: = Twicimage.Create; - WIC. LoadFromFile (afilename); + alienform_pngfromgraphic (Aform, WIC); - WIC. Free; + End; A procedureAlienform_pngfromresource (aform:tform; resname:string; Restype:pwidechar; Instance:hinst); at var - Wic:twicimage; - R:tresourcestream; - begin - ifInstance =0 Then -Instance: =hinstance; inr: = Tresourcestream.Create(Instance, Resname, restype); -WIC: = Twicimage.Create; to WIC. Loadfromstream (r); + alienform_pngfromgraphic (Aform, WIC); - WIC. Free; the R.free; * End; $ procedurealienform_pngfromgraphic (aform:tform; agraphic:tgraphic);Panax Notoginseng var - ptdst, Ptsrc:tpoint; the size:tsize; + blendfunction:tblendfunction; A Bmp:tbitmap; the begin +BMP: = Tbitmap.Create; - bmp. Assign (agraphic); $PTDST: =Point (Aform.left, aform.top); $PTSRC: = Point (0,0); -SIZE.CX: =Agraphic.width; -Size.cy: =Agraphic.height; theBLENDFUNCTION.BLENDOP: =Ac_src_over; -Blendfunction.blendflags: =0;WuyiBlendfunction.sourceconstantalpha: = $FF;//Transparency theBlendfunction.alphaformat: =Ac_src_alpha; - SetWindowLong (Aform.handle, Gwl_exstyle, GetWindowLong (Aform.handle, WuGwl_exstyle)orws_ex_layered); - Updatelayeredwindow (Aform.handle, About AForm.Canvas.Handle, $ @ptDst, - @Size, - bmp. Canvas.handle, - @ptSrc, A 0, + @BlendFunction, the ulw_alpha); - bmp. Free (); $ End; the End. the the //2. Calling Methods the proceduretform2.formcreate (sender:tobject); - begin inAlienform_pngfromfile (Form2,'e:\ untitled. PNG'); the End;
Delphi Special Window png