1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| procedure TForm1.Button1Click(Sender: TObject);
type
TFPCustomInterpolationClass = class of TFPCustomInterpolation;
var
Filtres: array[0..2] of TFPCustomInterpolationClass;
SourceBitmap, DestBitmap: TBitmap;
DestWidth, DestHeight: integer;
DestIntfImage, SourceIntfImage: TLazIntfImage;
DestCanvas: TLazCanvas;
begin
Filtres[0]:=TFPSharpInterpolation; // hérite directement de TFPCustomInterpolation (lazcanvas.pas)
Filtres[1]:=TMitchelInterpolation; // hérite de TFPBaseInterpolation, qui hérite de TFPCustomInterpolation (fpcanvas.pas)
Filtres[2]:=TLanczosInterpolation; // idem (extinterpolation.pas)
// Using the non-native StretchDraw from LazCanvas ; from : http://wiki.freepascal.org/Developing_with_Graphics
//Prepare the source
SourceBitmap:=TBitmap.Create;
SourceBitmap.LoadFromFile('c:\tests\lena.bmp'); // 512x512
Image1.Picture.Bitmap.Assign(SourceBitmap); // vérification que l'image a bien été chargée
SourceIntfImage := TLazIntfImage.Create(0, 0);
SourceIntfImage.LoadFromBitmap(SourceBitmap.Handle, 0);
// Prepare the destination
DestWidth:=400;
DestHeight:=400;
DestBitmap := TBitmap.Create;
DestBitmap.Width:=DestWidth;
DestBitmap.Height:=DestHeight;
DestIntfImage := TLazIntfImage.Create(0, 0);
DestIntfImage.LoadFromBitmap(DestBitmap.Handle, 0);
DestCanvas := TLazCanvas.Create(DestIntfImage);
// Execute the stretch draw via TFPSharpInterpolation
DestCanvas.Interpolation := Filtres[0].Create;
DestCanvas.StretchDraw(0, 0, DestWidth, DestHeight, SourceIntfImage);
// Reload the image into the TBitmap
DestBitmap.LoadFromIntfImage(DestIntfImage);
Image2.Picture.Bitmap.Assign(DestBitmap); // vérification bien exécuté
// 2ème redimensionnement
DestWidth:=800;
DestHeight:=800;
DestBitmap.Width:=DestWidth;
DestBitmap.Height:=DestHeight;
DestIntfImage.LoadFromBitmap(DestBitmap.Handle, 0);
DestCanvas.StretchDraw(0, 0, DestWidth, DestHeight, SourceIntfImage);
// Reload the image into the TBitmap
DestBitmap.LoadFromIntfImage(DestIntfImage);
Image3.Picture.Bitmap.Assign(DestBitmap); // vérification bien exécuté
SourceIntfImage.Free;
DestCanvas.Interpolation.Free;
DestCanvas.Free;
DestIntfImage.Free;
SourceBitmap.Free;
DestBitmap.Free;
end; |
Partager