Delphi 2010 新增功能之: TWICImage 類[3] - 影象的比例變換
阿新 • • 發佈:2020-12-27
TWICImage 的 Width、Height 屬性, 可以讀取但不能賦值.
調整 TWICImage 的大小、比例, 可以通過 IWICBitmapScaler 介面.
//IWICBitmapScaler.Initialize 函式有四種比例變換的演算法: WICBitmapInterpolationModeNearestNeighbor = 0; WICBitmapInterpolationModeLinear = $1; WICBitmapInterpolationModeCubic = $2; WICBitmapInterpolationModeFant = $3;
測試程式碼:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses Wincodec; procedureTForm1.Button1Click(Sender: TObject); var WicImg: TWICImage; Factory: IWICImagingFactory; Scaler: IWICBitmapScaler; {影象比例變換介面} begin WicImg := TWICImage.Create; WicImg.LoadFromFile('c:\temp\test.jpg'); Factory := WicImg.ImagingFactory; Factory.CreateBitmapScaler(Scaler); Scaler.Initialize(WicImg.Handle, WicImg.Width div2, WicImg.Height div 3, WICBitmapInterpolationModeFant); WicImg.Handle := IWICBitmap(Scaler); Canvas.Draw(0, 0, WicImg); Scaler := nil; Factory := nil; WicImg.Free; end; end.