delphi - VCL.Bitmap To FMX.Bitmap -
i found code on web, fmx.bitmap not have scanline. possible copy or draw vcl.tbitmap fmx.bitmap somehow?
{$ifdef mswindows} type tbitmap = fmx.types.tbitmap; tvclbitmap = vcl.graphics.tbitmap; procedure takescreenshot(dest: fmx.types.tbitmap); var dc: hdc; size: tpointf; vclbitmap: tvclbitmap; y: integer; begin vclbitmap := nil; //size := fmx.platform.ifmxscreenservice.getscreensize; dc := getdc(0); try vclbitmap := tvclbitmap.create; vclbitmap.pixelformat := pf32bit; vclbitmap.setsize(trunc(size.x), trunc(size.y)); bitblt(vclbitmap.canvas.handle, 0, 0, vclbitmap.width, vclbitmap.height, dc, 0, 0, srccopy); dest.setsize(vclbitmap.width, vclbitmap.height); { format of fmx bitmap , 32 bit vcl bitmap same, copy scanlines. - not true- fmx bitmap not have scanline? } y := dest.height - 1 downto 0 move(vclbitmap.scanline[y]^, dest.scanline[y]^, dest.width * 4); {dest.canvas.drawbitmap(); not possible assign or draw} releasedc(0, dc); vclbitmap.free; end; end; {$endif}
you can use stream :
{$ifdef mswindows} type tvclbitmap = vcl.graphics.tbitmap; procedure takescreenshot(dest: tbitmap); var dc: hdc; size: tpointf; vclbitmap: tvclbitmap; y: integer; ms: tmemorystream; begin ms := tmemorystream.create; vclbitmap := nil; // size := fmx.platform.ifmxscreenservice.getscreensize; dc := getdc(0); size.x := 500; size.y := 500; try vclbitmap := tvclbitmap.create; vclbitmap.pixelformat := pf32bit; vclbitmap.setsize(trunc(size.x), trunc(size.y)); bitblt(vclbitmap.canvas.handle, 0, 0, vclbitmap.width, vclbitmap.height, dc, 0, 0, srccopy); dest.setsize(vclbitmap.width, vclbitmap.height); { format of fmx bitmap , 32 bit vcl bitmap same, copy scanlines. - not true- fmx bitmap not have scanline? } vclbitmap.savetostream(ms); ms.position := 0; dest.loadfromstream(ms); ms.free; { dest.canvas.drawbitmap(); not possible assign or draw } releasedc(0, dc); vclbitmap.free; end; end; {$endif}
Comments
Post a Comment