Unable to use Scale method in TJPEGImage lazarus / 39-Graphics ---------------------------------------------------------------------- jrmit · 2010-01-27 16:24 TJPEGImage.Scale will not compile I am fairly new to Lazarus and was trying to port an application from Delphi for resizing Jpeg images to various screen resolutions (such as 1400x900), but ran into a problem with TJPEGImage.Scale.  It appears Scale is not supported in Lazarus' implementation of TJPEGImage.  Any suggestions. procedure TForm1.btnResizeImageClick(Sender: TObject); var   Jpeg1, Jpeg2: TJPEGImage;   TempBitmap : TBitMap;   CanvasRect : TRect;   x, nscale : integer;   aspect, maxaspect : single;   picdisp : String; begin   x := lbxFileListBox.ItemIndex;   picdisp := lbxFileListBox.Items;   TempBitmap := TBitmap.Create;   Jpeg1 := TJPEGImage.Create;   Jpeg2 := TJPEGImage.Create;   try     Jpeg1.LoadFromFile(picdisp);     //Find the width and height which fits inside the maximum rectangle     //while preserving the aspect ratio     aspect := Jpeg1.Width /Jpeg1.Height;     maxaspect := sw / sh;     if (aspect > maxaspect) then     begin       TempBitmap.Width := sw;       TempBitmap.Height := round(sw / aspect);     end     else     begin       TempBitmap.Width := round(sh * aspect);       TempBitmap.Height := sh;     end;     //Find the scale that causes the jpg to be as small as possible while     //still larger than the destination width and height.  This ensures that     //when the image is resampled it doesn't increase any dimention, only downsize     nscale :=floor(min(Jpeg1.Width / TempBitmap.Width, Jpeg1.Height /TempBitmap.Height));     case nscale of       0..1: begin         Jpeg1.Scale := jsFullSize;  Error: identifier indents no member "Scale"         nscale := 1;       end;       ... more code ---------------------------------------------------------------------- theo · 2010-01-27 17:34 There is Canvas.StretchDraw http://lazarus- ccr.sourceforge.net/docs/lcl/graphics/tcanvas.stretchdraw.html ---------------------------------------------------------------------- jrmit · 2010-01-28 15:35 Thanks, Theo.  Actually, I am already using canvas.stretchdraw further down in the code (not shown).  I will revise the code not to use TJPEGImage.Scale. ---------------------------------------------------------------------- jrmit · 2010-03-25 15:34 Since JPEGImage.Scale and Scanline were not available in Lazarus I modified the resize (resample) procedure using some code derived from (www.efg2.com/Lab ImageProcessing/AspectRatio.htm).     Jpeg1.LoadFromFile(picdisp);     .     .      if   Jpeg1.Width / Jpeg1.Height  <  sw / sh then     begin       CanvasRect.Top    := 0;       CanvasRect.Bottom := NBitmap.Height;       wt := MathRound((NBitmap.Height * Jpeg1.Width) / Jpeg1.Height);       Half := (NBitmap.Width - wt) div 2;       CanvasRect.Left  := Half;       CanvasRect.Right := CanvasRect.Left + wt;     end     else     begin       CanvasRect.Left    := 0;       CanvasRect.Right   := NBitmap.Width;       ht := MathRound((NBitmap.Width * Jpeg1.Height) / Jpeg1.Width);       Half := (NBitmap.Height - ht) div 2;       CanvasRect.Top    := Half;       CanvasRect.Bottom := CanvasRect.Top + ht;     end;     .     .   end; Read More: microguyscube.com/index.php/image-modify-procedure-for- lazarus John www.microguyscube.com ---------------------------------------------------------------------- derek.john.evans · 2013-02-02 04:20 I also wanted the Scale property in Lazarus. I tried using TFPMemoryImage and TFPReaderJpeg, but the images came out with pixels missing. But, I found this solution: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses FPReadJPEG, IntfGraphics; // May require other units type   TJPEGImagePlus = class(TJPEGImage)  private    FScale: TJPEGScale;  protected    procedure InitializeReader(AImage: TLazIntfImage;      AReader: TFPCustomImageReader); override;  public    property Scale: TJPEGScale read FScale write FScale;  end; procedure TJPEGImagePlus.InitializeReader(AImage: TLazIntfImage;  AReader: TFPCustomImageReader);begin  (AReader as TFPReaderJpeg).Scale := FScale;  inherited;end; Then just load the JPEG's as you normally do via TJpegImage: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   LJPEGImage := TJPEGImagePlus.Create;  LJPEGImage.Scale := jsEighth;  LJPEGImage.LoadFromFile(AFileName);  FPicture.Assign(LJPEGImage);  FreeAndNil(LJPEGImage);  Hope that helps people. ---------------------------------------------------------------------- BigChimp · 2013-02-02 07:55 Guys, Great that you have improvements for Lazarus. If they're good enough, could you please post them as patches to bugtracker issues? That way, they won't be forgotten or overlooked. See e.g. http://wiki.lazarus.freepascal.org/Creating_A_Patch and http://wiki.lazarus.freepascal.org/How_do_I_create_a_bug_report Thanks a lot!