Recent

Author Topic: Is TFPImageCanvas.StretchDraw slow  (Read 418 times)

Zaher

  • Hero Member
  • *****
  • Posts: 604
    • parmaja.com
Is TFPImageCanvas.StretchDraw slow
« on: December 28, 2019, 12:04:19 pm »
My project is small bitmap font editor, I am adding new control to edit small png transparent image with alpha pixles.

Drawing pixels started being slow at size > 64, with scaling it 10 times

here the part of code of painting it
Code: Pascal  [Select][+][-]
  1. var
  2.   Img: TBitmap;
  3.   fpimage: TLazIntfImage;
  4. begin
  5.   if IsChanged then
  6.   begin
  7.     IsChanged := False;
  8.     if (PaintTool <> nil) and not (ptsDirect in PaintTool.Style) then
  9.     begin
  10.       ScrachImage.CopyPixels(FImage);
  11.       PaintTool.Paint(FScrachCanvas);
  12.       fpimage := ScrachImage;
  13.     end
  14.     else
  15.       fpimage := Image;
  16.  
  17.     ScaledImage.CopyPixels(BackgroundImage);
  18.     ScaledCanvas.DrawingMode := dmAlphaBlend;
  19.     //ScaledCanvas.Interpolation := TFPBoxInterpolation.Create; moved to after create ScaledCanvas
  20.     ScaledCanvas.StretchDraw(0, 0, ScaledImage.Width, ScaledImage.Height, fpimage);
  21.   end;
  22.  
  23.   Img := TBitmap.Create;
  24.   try
  25.     Img.LoadFromIntfImage(ScaledImage);
  26.     vCanvas.Draw(0, 0, Img);
  27.   finally
  28.     Img.Free;
  29.   end;
  30. end;
  31.  

and images created here
Code: Pascal  [Select][+][-]
  1.   FImage := TLazIntfImage.Create(cDefaultWidth, cDefaultHeight, [riqfRGB, riqfAlpha]);
  2.   FCanvas := TFPImageCanvas.Create(FImage);
  3.   FDrawer := TIntfFreeTypeDrawer.Create(FImage);
  4.   FFont := TFreeTypeFont.Create;
  5.   FFont.Name := 'c:\Windows\fonts\Arial.ttf';
  6.   FFont.SizeInPixels := 9;
  7.   FFont.Hinted := False;
  8.   FFont.ClearType := False;
  9.   FFont.Quality := grqLowQuality;
  10.  
  11.   FScrachImage := TLazIntfImage.CreateCompatible(FImage, cDefaultWidth, cDefaultHeight);
  12.   FScrachCanvas := TFPImageCanvas.Create(FScrachImage);
  13.  
  14.   ScaledImage := TLazIntfImage.CreateCompatible(ScrachImage, ScrachImage.Width * DotSize, ScrachImage.Height * DotSize);
  15.   ScaledCanvas := TFPImageCanvas.Create(ScaledImage);
  16.   ScaledCanvas.Interpolation := TFPBoxInterpolation.Create;
  17.  
  18.   BackgroundImage := TLazIntfImage.CreateCompatible(ScrachImage, ScrachImage.Width * DotSize, ScrachImage.Height * DotSize);
  19.   BackgroundCanvas := TFPImageCanvas.Create(BackgroundImage);
  20.  
  21.   FHistory := TntvHistory.Create;
  22.  
  23.   SetSize(cDefaultWidth, cDefaultHeight);
  24.  

my project is opensource https://github.com/parmaja/minictrls/blob/master/native/ntvPixelGrids.pas#L612

Where is my fault, or Is there any way to make it faster painting or generating scaled image?

 

TinyPortal © 2005-2018