Jump to content

Recommended Posts

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
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:

image.thumb.png.6bd71aa91988e970c3bc37fc0cd058c1.png

 

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 by vfbb

Share this post


Link to post

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
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

  • Like 1

Share this post


Link to post
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
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

Is there a way to convert a svg (its in a tmemorystream) to png (to another tmemorystream)?

Share this post


Link to post

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
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
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;

 

  • Like 1

Share this post


Link to post

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

@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

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 by martincg
Worked out how to use the second parameter

Share this post


Link to post

 

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 by martincg

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×