this method is working. thanks
On Sat, Jul 7, 2012 at 9:43 PM, Bernd <prof7...@gmail.com> wrote: > 2012/7/7 tazio mirandola <dev...@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@lists.freepascal.org >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> > > > _______________________________________________ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > 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.
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal