hsauro 37 Posted December 28, 2021 All I actually want is to draw text that is orientated 90 degrees to the horizontally, ie vertical. No fancy paths to follow, just a straight line. I can currently do it by rotating the image first by 90 degress, writing the text horizontally, then rotate the image back -90 degrees. Share this post Link to post
vfbb 280 Posted December 28, 2021 (edited) 6 hours ago, hsauro said: All I actually want is to draw text that is orientated 90 degrees to the horizontally, ie vertical. No fancy paths to follow, just a straight line. I can currently do it by rotating the image first by 90 degress, writing the text horizontally, then rotate the image back -90 degrees. The correct way is to rotate only the drawing you are doing, in this case the text. For this you must rotate by ISkCanvas: uses System.Math, System.Math.Vectors, Skia; procedure TForm1.SkPaintBox1Draw(ASender: TObject; const ACanvas: ISkCanvas; const ADest: TRectF; const AOpacity: Single); var LDest: TPointF; begin LDest := PointF(150, 50); ACanvas.Clear(TAlphaColors.Null); ACanvas.Save; try ACanvas.DrawSimpleText('Skia4Delphi 1', LDest.X, LDest.Y, TSkFont.Create, TSkPaint.Create); ACanvas.Rotate(90); LDest := LDest * TMatrix.CreateRotation(DegToRad(-90)); ACanvas.DrawSimpleText('Skia4Delphi 2', LDest.X, LDest.Y, TSkFont.Create, TSkPaint.Create); finally ACanvas.Restore; end; end; Results: Note: I made the adjustment of LDest with TMatrix.CreateRotation because when rotating the canvas, its X and Y of DrawSimpleText are also rotated. Edited December 28, 2021 by vfbb Share this post Link to post
hsauro 37 Posted December 28, 2021 Thanks for the example, I think this will be useful to others as well. Share this post Link to post
softtouch 5 Posted March 15, 2023 How can I get the image forma (jpg, png etc.) of an image stored in a memorystream with skia4delphi? Share this post Link to post
vfbb 280 Posted March 15, 2023 17 minutes ago, softtouch said: How can I get the image forma (jpg, png etc.) of an image stored in a memorystream with skia4delphi? Just to discover the image format? You can use the TSkCodec.MakeFromStream(LStream).EncodedImageFormat 1 Share this post Link to post
softtouch 5 Posted March 15, 2023 17 minutes ago, vfbb said: Just to discover the image format? You can use the TSkCodec.MakeFromStream(LStream).EncodedImageFormat Great, thanks, that was it I was looking for. Another short question: Why cant it encode bmp format and gif? Share this post Link to post
vfbb 280 Posted March 15, 2023 18 minutes ago, softtouch said: Why cant it encode bmp format and gif? Google Skia decision. Just as FMX decided to only encode PNG or JPEG, Skia decided to only encode PNG, JPEG and WEBP (the same goes for other languages). Maybe it's because they only adopted the formats that are widely used on all platforms. Decoding a variety of formats, which already occurs, is really the most important thing. In addition, the accepted formats already meet the needs of the vast majority. Share this post Link to post
softtouch 5 Posted March 22, 2023 Is there a way to convert a svg (its in a tmemorystream) to png (to another tmemorystream)? Share this post Link to post
Kyle Miller 1 Posted April 4, 2023 Basic question: Skia4Delphi is more than GPU integration. It requires the GPU. Correct? I ask because I tried running some apps with Skia enabled on Terminal server, and they crashed hard. They run fine on local desktop. Share this post Link to post
vfbb 280 Posted April 10, 2023 On 4/4/2023 at 2:45 PM, Kyle Miller said: Basic question: Skia4Delphi is more than GPU integration. It requires the GPU. Correct? I ask because I tried running some apps with Skia enabled on Terminal server, and they crashed hard. They run fine on local desktop. The library itself does not require a GPU. There is a raster backend that uses only CPU. It should work normally, I even ran it on Windows Server normally. On the other hand, I saw that SkiaSharp already had problems with the Nano Server, so the more information you can give, the better it will be. I suggest opening an issue on the project's github with all the information you have. Skia4Delphi GitHub - Issues Share this post Link to post
vfbb 280 Posted April 10, 2023 On 3/22/2023 at 1:30 PM, softtouch said: Is there a way to convert a svg (its in a tmemorystream) to png (to another tmemorystream)? Yes! See an example: uses Skia, Skia.FMX {or Skia.Vcl}; procedure SvgStreamToImageStream(const AInputSvgStream, AOutputImageStream: TStream; const AImageWidth, AImageHeight: Integer; const AFormat: TSkEncodedImageFormat = TSkEncodedImageFormat.PNG); var LSurface: ISkSurface; LSvgBrush: TSkSvgBrush; LSvgBytes: TBytes; begin SetLength(LSvgBytes, AInputSvgStream.Size - AInputSvgStream.Position); AInputSvgStream.ReadBuffer(LSvgBytes, Length(LSvgBytes)); LSurface := TSkSurface.MakeRaster(AImageWidth, AImageHeight); LSurface.Canvas.Clear(TAlphaColors.Null); LSvgBrush := TSkSvgBrush.Create; try LSvgBrush.Source := TEncoding.UTF8.GetString(LSvgBytes); LSvgBrush.Render(LSurface.Canvas, RectF(0, 0, AImageWidth, AImageHeight), 1); finally LSvgBrush.Free; end; LSurface.MakeImageSnapshot.EncodeToStream(AOutputImageStream, AFormat); end; 1 Share this post Link to post
martincg 0 Posted January 9 I want to convert several programs to use Skia for Delphi so that the drawings are antialiased. (Delphi 11.1) The easiest way seems to be to use TBitmap.SkiaDraw, then TImage.Canvas.Copyrect to get the drawing onto the image. How do I do this but keep what was drawn on the image before? Say I have one procedure which draws stgae1. Then later, I want to draw stage2 over stage1. So far I haven't understaood how to 'update' animage. Using a TBitmap and a TImage is good for my requirements because the original programs all drew on bitmaps which were then copied to an image. But if I copy from the stage1 on the image canvas to a bitmap and then use SKiaDraw on the bitmap to draw stage2 then stage1 is lost. Can anyone suggest what should be done? Share this post Link to post
vfbb 280 Posted January 10 @martincg Bitmap.SkiaDraw have a second optional argument, AStartClean: Boolean, and when False you will not lost its content. Share this post Link to post
martincg 0 Posted January 10 (edited) Oh, thank you vfbb. I should have seen that!. It does exactly what I want. I can do this- ABitMap.SkiaDraw(dodraw2, false); or if I use an anonomous procedure it works like this ABitMap.SkiaDraw(procedure (const ACanvas:ISKCanvas) begin //code end, DoStartClean); //<--second parameter here. BTW, the conversion I have done to Skia so far using SkiaDraw is a lot slower than VCL canvas.draw.... I haven't measured it but as a guess I would think 5 times slower. Is that to be expected? Edited January 10 by martincg Worked out how to use the second parameter Share this post Link to post
martincg 0 Posted January 11 (edited) SkiDraw stops Image1MouseMove from firing. When I use SkiDraw, somehow it stops my image1mousemove being called. The effect that I see with this is that when I try to drag an image it appears to move only when the mouse movement stops. If I add a line in my Image1MouseMove procedure to update a label with the mouse coordinates then the label caption doesn't change while the mouse is moving but updates when the mouse movement stops. This doesn't happen with VCL standard drawing. With that I can drag the drawing around as fast as I can move the mouse. Update; Although it appeared to stop on mousemove being called I found that the image was being redrawn but not repainted. By adding image1.Repaint the speed is back to normal. I don't have an understanding of why using canvas,SkiaSDraw stops the form from repainting. Edited January 12 by martincg Share this post Link to post
SchobiHH 0 Posted January 31 (edited) - Edited January 31 by SchobiHH Delete Share this post Link to post