this method is working. thanks<div><br></div><div><br><br><div class="gmail_quote">On Sat, Jul 7, 2012 at 9:43 PM, Bernd <span dir="ltr"><<a href="mailto:prof7bit@gmail.com" target="_blank">prof7bit@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">2012/7/7 tazio mirandola <span dir="ltr"><<a href="mailto:devsmt@gmail.com" target="_blank">devsmt@gmail.com</a>></span><br>
<div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>hi all,</div><div><br></div><div>i'm trying to resize a jpg via fpc-image, this is the relevant code(adapted from <a href="http://wiki.freepascal.org/fcl-image" target="_blank">http://wiki.freepascal.org/fcl-image</a>):</div>
<div>
<br></div></blockquote></div><div><br><br>for resizing you should use StretchDraw() from the TCanvas object:<br><br><br> ImageOriginal := TFPMemoryImage.Create(0, 0);<br> ImageOriginal.LoadFromStream(ImageStream, ImageReader);<br>
<br> // scale the image to 64*64<br> ImageScaled := TFPMemoryImage.Create(64, 64);<br> {$warnings off} // contains some abstract methods (must be FCL bug)<br> CanvasScaled := TFPImageCanvas.Create(ImageScaled);<br>
{$warnings on}<br> CanvasScaled.StretchDraw(0, 0, 64, 64, ImageOriginal);<br> <br> // now ImageScaled contains the scaled image<br> // save it and then free all the objects.<br><br>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.<br>
<br><br><br><br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="h5"><div></div><div><br></div><div><font face="'courier new', monospace">uses</font></div>
<div><div><font face="'courier new', monospace"> fpimage, fpcanvas, FPImgCanv, fpreadjpeg,fpwritejpeg;</font></div><div>
<font face="'courier new', monospace"> </font></div></div><div><div><font face="'courier new', monospace">procedure TImgResize.Resample(AFileName:string);</font></div><div><font face="'courier new', monospace">var</font></div>
<div><font face="'courier new', monospace"> Image : TFPCustomImage;</font></div><div><font face="'courier new', monospace"> writer : TFPCustomImageWriter;</font></div><div><font face="'courier new', monospace"> Reader : TFPReaderJPEG;</font></div>
<div><font face="'courier new', monospace"> Canvas : TFPCustomCanvas;</font></div><div><font face="'courier new', monospace">begin</font></div><div><font face="'courier new', monospace"> // Create an image</font></div>
<div><font face="'courier new', monospace"> Image := TFPMemoryImage.Create(224,150);</font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> Reader := TFPReaderJPEG.Create;</font></div>
<div><font face="'courier new', monospace"> Image.LoadFromFile(AFileName (*, Reader*) );</font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> //Image.SetSize(224,150);</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> // Attach the image to the canvas</font></div><div><font face="'courier new', monospace"> Canvas := TFPImageCanvas.Create(image);</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> // Create the writer</font></div><div><font face="'courier new', monospace"> Writer := TFPWriterJPEG.Create;</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> // Save to file</font></div><div><font face="'courier new', monospace"> Image.SetSize(224,150);</font></div>
<div><font face="'courier new', monospace"> Image.SaveToFile(AFileName+'b.jpg' (*, writer*) );</font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> Canvas.Free;</font></div>
<div><font face="'courier new', monospace"> Image.Free;</font></div><div><font face="'courier new', monospace"> Writer.Free;</font></div><div><font face="'courier new', monospace">end; </font> </div>
</div><div><br></div><div>actually, Image.SetSize(224,150); causes half of the resulting image being black!</div><div>is it a bug or am i colling it wrongly?</div><br><br>--<br>Tazio Mirandola<br>Consulenza Software e Web<br>
Cel:<a href="tel:348%200836782" value="+393480836782" target="_blank">348 0836782</a> Skype:tazio.mirandola <a href="Http://evidenceweb.it" target="_blank">Http://evidenceweb.it</a><br><table border="0" cellpadding="0" cellspacing="0" width="550">
<tbody></tbody></table><br>
<br></div></div><div class="im">_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br></div></blockquote></div><br>
<br>_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><br><br><table border="0" cellpadding="0" cellspacing="0" width="550">
<tbody><tr><td style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><h1 style="font:normal normal bold 23px/normal arial;margin-top:5px;margin-right:0px;margin-bottom:5px;margin-left:0px">Tazio Mirandola</h1>
<h2 style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;font:normal normal normal 17px/normal arial;color:rgb(110,178,0)">Consulenza Software e Web</h2>
<p style="margin-top:5px;margin-right:0px;margin-bottom:5px;margin-left:0px"><strong>Cel:<a value="+393480836782" style="color:rgb(17,85,204)">348 0836782</a> Skype:tazio.mirandola Http://<a href="http://www.evidenceweb.it/" style="color:rgb(110,178,0)" target="_blank">evidenceweb.it</a></strong></p>
<br><p style="width:550px;margin-top:3px;margin-right:auto;margin-bottom:3px;margin-left:auto;font:normal normal normal 10px/normal arial,sans-serif;color:rgb(153,153,153)">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.</p>
</td></tr></tbody></table><br>
</div>