[fpc-pascal] bug fpc-image

Bernd prof7bit at gmail.com
Sat Jul 7 21:43:17 CEST 2012


2012/7/7 tazio mirandola <devsmt at gmail.com>

> hi all,
>
> i'm trying to resize a jpg via fpc-image, this is the relevant
> code(adapted from http://wiki.freepascal.org/fcl-image):
>
>

for resizing you should use StretchDraw() from the TCanvas object:


      ImageOriginal := TFPMemoryImage.Create(0, 0);
      ImageOriginal.LoadFromStream(ImageStream, ImageReader);

      // scale the image to 64*64
      ImageScaled := TFPMemoryImage.Create(64, 64);
      {$warnings off} // contains some abstract methods (must be FCL bug)
      CanvasScaled := TFPImageCanvas.Create(ImageScaled);
      {$warnings on}
      CanvasScaled.StretchDraw(0, 0, 64, 64, ImageOriginal);

      // now ImageScaled contains the scaled image
      // save it and then free all the objects.

There is also a complete example in the 2.7 trunk but that example contains
a bug, it will leak memory because it does not free all objects.







>
> uses
>   fpimage, fpcanvas, FPImgCanv,  fpreadjpeg,fpwritejpeg;
>
> procedure TImgResize.Resample(AFileName:string);
> var
>     Image : TFPCustomImage;
>     writer : TFPCustomImageWriter;
>     Reader : TFPReaderJPEG;
>     Canvas : TFPCustomCanvas;
> begin
>   // Create an image
>   Image := TFPMemoryImage.Create(224,150);
>
>   Reader := TFPReaderJPEG.Create;
>   Image.LoadFromFile(AFileName (*, Reader*) );
>
>   //Image.SetSize(224,150);
>
>   // Attach the image to the canvas
>   Canvas := TFPImageCanvas.Create(image);
>
>   // Create the writer
>   Writer := TFPWriterJPEG.Create;
>
>   // Save to file
>   Image.SetSize(224,150);
>   Image.SaveToFile(AFileName+'b.jpg' (*, writer*) );
>
>   Canvas.Free;
>   Image.Free;
>   Writer.Free;
> end;
>
> actually, Image.SetSize(224,150); causes half of the resulting image being
> black!
> is it a bug or am i colling it wrongly?
>
>
> --
> Tazio Mirandola
> Consulenza Software e Web
> Cel:348 0836782 Skype:tazio.mirandola Http://evidenceweb.it
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20120707/d9e4771d/attachment.html>


More information about the fpc-pascal mailing list