Welcome

首页 / 软件开发 / Delphi / 再学GDI+[89]: TGPImage(9) - 图像缩放时的质量(算法)

再学GDI+[89]: TGPImage(9) - 图像缩放时的质量(算法)2012-05-27 博客园 万一本例效果图:

代码文件:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI;
var
n: Single = 0.75; {缩放倍数}
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Align := alRight;
with ListBox1.Items do
begin
add("InterpolationModeInvalid ");
add("InterpolationModeDefault ");
add("InterpolationModeLowQuality ");
add("InterpolationModeHighQuality ");
add("InterpolationModeBilinear ");
add("InterpolationModeBicubic ");
add("InterpolationModeNearestNeighbor ");
add("InterpolationModeHighQualityBilinear");
add("InterpolationModeHighQualityBicubic ");
end;
ListBox1.ItemIndex := 1;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
g: TGPGraphics;
img: TGPImage;
rt: TGPRectF;
begin
g := TGPGraphics.Create(Self.Canvas.Handle);
img := TGPImage.Create("C: emp est.png");
g.DrawImage(img, 4, 4, img.GetWidth, img.GetHeight);
rt := MakeRect(4+img.GetWidth+4, 4, img.GetWidth * n, img.GetHeight * n);
g.SetInterpolationMode(ListBox1.ItemIndex - 1);
g.DrawImage(img, rt, 0, 0, img.GetWidth, img.GetHeight, UnitPixel);
img.Free;
g.Free;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
Repaint;
end;
end.