Jump to content
martincg

Copy from a LSKSurface to a TSKPaintBox

Recommended Posts

Posted (edited)

I want to draw on a LSKSurface and then update the TSKPaintBox with the result.

The problem I have is that the drawing shown in the SKPaintBox does not appear to be antialiased.

If I draw straight into the paintbox canvas all is fine, and if I draw in the surface canvas and save a snapshot to a png image then the result is also fine.


//=============CanvasA is canvas for a TSKPaintBox ===================
procedure TfrmMain.drawTest(canvasA: ISkCanvas; targetRect: TRectF);
var
  paint: ISkPaint;
  LSurface: ISKSurface;
   LFont1:ISkFont;
   LTypeface:ISkTypeface;
   rot:single;
   tempimg:ISKImage;
   RWidth,RHeight:integer;
   cancan:ISKCanvas;
begin
  RWidth := round(targetRect.Width);
  RHeight := round(targetRect.Height);
  canvasA.Scale(1,1);

  LSurface := TSkSurface.MakeRaster(RWidth, RHeight);
  Lsurface.Canvas.Scale(1,1);

    //cancan := canvasA;
  cancan := LSurface.canvas;


  cancan.Clear(TAlphaColors.Aqua); // refresh canvas

  paint := TSKPaint.Create;
  Paint.SetColorF(TAlphaColorF.Create(TALphaColorRec.Blue));
  paint.AntiAlias := true;
  paint.StrokeWidth := 1;//6;
  paint.Style := TSkPaintStyle.Stroke; // .fill .strokeandfill

  cancan.DrawLine(0, 0, 200, 700, paint);
  cancan.drawcircle(500,500,200,paint);

  LSurface.MakeImageSnapshot.EncodeToFile('C:\temp\skia1.png');//looks OK - no jaggies

  tempimg := lsurface.MakeImageSnapshot;

  if cancan <> canvasA then
   canvasA.DrawImageRect(tempimg,targetRect,targetRect);// has jaggies

end;

Can someone explain where I am going wrong?

Edited by martincg
typos

Share this post


Link to post
Posted (edited)

The solution is (partly)

Keep the original TImage and the TBitmap.

Draw on the bitmap using Bitmap.SkiDraw(procedure(Const ACanvas:ISKCanvas)

                         begin

                         //code to draw using Skia draw functions

                              ..

                      end);

 

Then do

   image.canvas.copyrect(rect(...), bitmap.canvas, rect(..))

 

This works for me although I have the following gripes and problems.

A) The drawing procedure called can be aanonomous as I showed or it can be a procedure but, as far as I have been able to find, I cannot see how to have the procedure as a sub procedure in the same procedure so that the variables are shared.  This makes the drawing process extremely awkward especially if I want to do B.

B) I want to draw on the image, and then draw over the top of what was first drawn.  If anyone can tell me how to do that then please do. All attempts I have made so far have failed. For example, if I copy the image to a bitmap then use SKiaDraw on the bitmap the original image information is wiped.

 

I have no doubt that my ignorance is the main problem so if anyone can point me to a good source of learning and examples for SKI for DElphi that would be great. (Video tutorials arer no help to me.)

 

Edited by martincg

Share this post


Link to post
3 hours ago, martincg said:

if I copy the image to a bitmap then use SKiaDraw on the bitmap the original image information is wiped.

Hi @martincg! I answered you on another topic with the same issue. To preserve the old content of the bitmap when starts draw with skia, you should call Bitmap.SkiaDraw(..., False);

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

×