本例效果圖:
代碼文件: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:temptest.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.object Form1: TForm1
縮放時的算法模式(TInterpolationMode 枚舉)列表:
Left = 0
Top = 0
Caption = 'Form1'
ClIEntHeight = 213
ClIEntWidth = 550
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
OnCreate = FormCreate
OnPaint = FormPaint
PixelsPerInch = 96
TextHeight = 13
object ListBox1: TListBox
Left = 357
Top = 32
Width = 185
Height = 97
ItemHeight = 13
TabOrder = 0
OnClick = ListBox1Click
end
endInterpolationModeInvalid = -1; {等效於 QualityMode 枚舉的 Invalid 元素. }
InterpolationModeDefault = 0; {指定默認模式. }
InterpolationModeLowQuality = 1; {指定低質量插值法. }
InterpolationModeHighQuality = 2; {指定高質量插值法. }
InterpolationModeBilinear = 3; {指定雙線性插值法. 不進行預篩選. 將圖像收縮為原始
大小的 50% 以下時,此模式不適用. }
InterpolationModeBicubic = 4; {指定雙三次插值法. 不進行預篩選. 將圖像收縮為原始
大小的 25% 以下時,此模式不適用. }
InterpolationModeNearestNeighbor = 5; {指定最臨近插值法. }
InterpolationModeHighQualityBilinear = 6; {指定高質量的雙線性插值法. 執行預篩選以確保高質量
的收縮. }
InterpolationModeHighQualityBicubic = 7; {指定高質量的雙三次插值法. 執行預篩選以確保高質量
的收縮. 此模式可產生質量最高的轉換圖像. }