gwideman 0 Posted November 8 I would like to use VCL.Skia.TSkSvg to render an SVG, and then copy the resulting bitmap to another control, for example a TImage. I though that might be possible using TSkSvg's Canvas, but that's protected, so presumably not the way to do it. I noticed that FMX.Skia.TSkSvg has a (inherited) PaintTo method, but the VCL version does not. So what is the correct approach? Thanks! For bonus points -- is it possible to perform the above with the TSkSvg control not visible on the Form? Share this post Link to post
Rollo62 538 Posted November 8 (edited) Maybe that can help? ( but you have to learn German first 🙂 ) https://www.delphipraxis.net/213780-bild-auf-timage-mit-svg-grafiken-zusammenfuehren-skia.html Edited November 8 by Rollo62 Share this post Link to post
Vincent Gsell 11 Posted November 8 (edited) Doc on Skia Github page contains usefull code to convert svg to bmp : https://github.com/skia4delphi/skia4delphi/blob/main/Documents/SVG.md From an skia's image (do not remomber if available from skSVG. https://docwiki.embarcadero.com/Libraries/Athens/en/FMX.Skia.SkImageToBitmap Edited November 8 by Vincent Gsell 1 Share this post Link to post
Lajos Juhász 295 Posted November 8 13 minutes ago, Vincent Gsell said: Doc on Skia Github page contains usefull code : https://docwiki.embarcadero.com/Libraries/Athens/en/FMX.Skia.SkImageToBitmap this is fmx while the question is about VCL. Share this post Link to post
Vincent Gsell 11 Posted November 8 (edited) 2 minutes ago, Lajos Juhász said: this is fmx while the question is about VCL. Right. https://docwiki.embarcadero.com/Libraries/Athens/en/Vcl.Skia.SkImageToBitmap On the same manner, the first link (github doc) is fully compatible with VCL. A great effort has been made in skia to support well the 2 frameworks. Edited November 8 by Vincent Gsell 1 Share this post Link to post
gwideman 0 Posted November 8 I appreciate your answers, but I'm still not completely understanding how to make this work... A couple of followup questions below: 9 hours ago, Vincent Gsell said: Doc on Skia Github page contains usefull code to convert svg to bmp : https://github.com/skia4delphi/skia4delphi/blob/main/Documents/SVG.md Are you referring to the Rendering SVG example? If so, I'm afraid that example is too incomplete to show how it relates to my task, which is essentially "input an SVG file, render it to a bitmap or canvas." In that example, it's not clear to me: where "ACanvas" comes what is the role of the procedure parameter in the SkiaDraw procedure. I infer that it takes part in rendering the SVG. But under what circumstances does SkiaDraw invoke it? Why so convoluted? I didn't find any doc on SkiaDoc,, so if there is doc for that procedure it might shed some light. 9 hours ago, Vincent Gsell said: From an skia's image (do not remomber if available from skSVG. https://docwiki.embarcadero.com/Libraries/Athens/en/FMX.Skia.SkImageToBitmap For VCL: function SkImageToBitmap(const AImage: ISkImage): TBitmap; Where do I get the ISkImage from? Thanks all! Share this post Link to post
Vincent Gsell 11 Posted November 9 (edited) Hi In fact, to draw it properly on a Bmp, there are some init and code to add : The technic to pass the proc allow you (not only, but it is uses as is) to concentrate yourself to your drawing process. I invite you to go to the implementation in FMX.Skia or VCL.Skia, to see what is done. (If you do not have source code, it is available github) -> In the code, IksCanvas comes directly for a Bitmap helper class, wich introduce the canvas from a dedicated surface. And again, the skia integration is very well done, because "high level" code between 2 framework is very same. -> So, here is the code you need to transfert your svg to your "vcl" control (I do it on VCL framework, it's been a long time that I do not open a new projet on it :)) uses System.IOUtils, //files. System.Types, //RectF System.Skia, VCL.Skia; Procedure Transfert; var LBitmap: TBitmap; begin LBitmap := TBitmap.Create(100, 100); try LBitmap.SkiaDraw( procedure (const ACanvas: ISKCanvas) var LSvgBrush: TSkSvgBrush; begin LSvgBrush := TSkSvgBrush.Create; try LSvgBrush.Source := TFile.ReadAllText('..\..\..\samples\panda.svg'); LSvgBrush.Render(ACanvas, RectF(0, 0, LBitmap.Width, LBitmap.Height), 1); finally LSvgBrush.Free; end; end); finally //Transfert into an VCL Control Form59.Image1.Picture.Assign(LBitmap); FreeAndNil(LBitmap); end; end; procedure TForm59.FormCreate(Sender: TObject); begin Transfert; end; Edited November 9 by Vincent Gsell Share this post Link to post
Vincent Gsell 11 Posted November 9 7 hours ago, gwideman said: Where do I get the ISkImage from? When you use skia directly, this interface come very quickly, and it will more easy to call. As I said in my first message, I do not remember if tskSVG component have an Image property : Certainly not, if you do not see it : But the code is interesting to see, again, in VCL.Skia. Share this post Link to post