Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-07

bug fpc-image

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

tazio mirandola

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

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
Mattias Gaertner
to tazio mirandola
Show quoted text 42 lines
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): 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?

It seems a bug in TFPMemoryImage.SetSize.
The move moves only w byte, but it should move w*SizeOf(TFPColor) byte. Please report.

BTW, SetSize does not scale the image.

Mattias

Bernd
to tazio mirandola: i'm trying to resize a jpg via fpc-image, this is the relevant code(adapted from…

2012/7/7 tazio mirandola

Show quoted text 6 lines
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.

Show quoted text 49 lines
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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
tazio mirandola
to Bernd

this method is working. thanks

Bernd wrote 89 lines
2012/7/7 tazio mirandola > 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 - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Tazio MirandolaConsulenza Software e Web *Cel:348 0836782 Skype:tazio.mirandola Http://evidenceweb.it<http://www.evidenceweb.it/> * privacy: Il trattamento dei vostri dati personali sarà improntato a liceità e correttezza. Non è permesso divulgare anche in parte o utilizzare il messaggio per finalità diverse o non autorizzate essendo questo messaggio riservato e l'utilizzo consentito esclusivamente al destinatario, per le finalità indicate e come prescritto dal D.LGS 196/2003.