Uses direct2d; Procedure tform1.formpaint (Sender: tobject); var CVS: tdirect2dcanvas; WIC: twicimage; R: trect; begin WIC: = twicimage. create; WIC. loadfromfile ('C: \ temp \ test.png '); CVS: = tdirect2dcanvas. create (canvas, clientrect); CVs. begindraw; CVs. draw (10, 10, WIC); R: = bounds (WIC. width Div 2 + 10, WIC. height Div 2 + 10, WIC. width Div 2, WIC. height Div 2); CVs. stretchdraw (R, WIC, 192); CVs. enddraw; CVs. free; WIC. free; end;
:
Redo the above example (through WIC) in a more primitive way ):
Uses direct2d, d2d1, wincodec, ActiveX; {function for creating an id2d1bitmap object from the specified file} function getd2d1bitmap (rendertarget: role; imgpath: string): role; var iwicfactory: iwicimagingfactory: iwicbitmapdecoder; iwicframedecode: iwicbitmapframedecode; iformatconverter: iwicformatconverter; begin {obtain the factory for creating a WIC} cocreateinstance (clsid_wicimagingfactory, nil, region, region, iwicfactory ); {open and obtain the decoded object} iwicfactory. createdecoderfromfilename (pwidechar (imgpath), guid_null, generic_read, wicdecodemetadatacheonload, iwicdecoder); {get the first frame} iwicdecoder. getframe (0, iwicframedecode); {Get format converter} iwicfactory. createformatconverter (iformatconverter); {convert to D2d compatible format} iformatconverter. initialize (iwicframedecode, guid_wicpixelformat32bpppbgra, wicbitmapdithertypenone, nil, 0, wicbitmappalettetypemediancut); {Get id2d1bitmap} rendertarget. convert (iformatconverter, nil, result); end; Procedure convert (Sender: tobject); var CVS: tdirect2dcanvas; ibitmap: id2d1bitmap; frect: td2drectf; fsize: Begin; begin CVS: = tdirect2dcanvas. create (canvas, clientrect); ibitmap: = getd2d1bitmap (CVS. rendertarget, 'c: \ temp \ test.png '); ibitmap. getsize (fsize); frect: = d2d1rectf (0, 0, fsize. width, fsize. height); CVs. begindraw; CVs. rendertarget. settransform (td2dmatrix3x2f. translation (10, 10); CVs. rendertarget. drawbitmap (ibitmap, @ frect); frect: = d2d1rectf (0, 0, fsize. width/2, fsize. height/2); CVs. rendertarget. settransform (td2dmatrix3x2f. translation (frect. right + 10, frect. bottom + 10); CVs. rendertarget. drawbitmap (ibitmap, @ frect, 0.75); CVs. enddraw; CVs. free; end;