程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 再學GDI+[89]: TGPImage(9) - 圖像縮放時的質量(算法)

再學GDI+[89]: TGPImage(9) - 圖像縮放時的質量(算法)

編輯:Delphi

本例效果圖:

代碼文件: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:\temp\test.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
 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
end
縮放時的算法模式(TInterpolationMode 枚舉)列表:InterpolationModeInvalid       = -1; {等效於 QualityMode 枚舉的 Invalid 元素. }
InterpolationModeDefault       = 0; {指定默認模式. }
InterpolationModeLowQuality     = 1; {指定低質量插值法. }
InterpolationModeHighQuality     = 2; {指定高質量插值法. }
InterpolationModeBilinear      = 3; {指定雙線性插值法. 不進行預篩選. 將圖像收縮為原始
                         大小的 50% 以下時,此模式不適用. }
InterpolationModeBicubic       = 4; {指定雙三次插值法. 不進行預篩選. 將圖像收縮為原始
                         大小的 25% 以下時,此模式不適用. }
InterpolationModeNearestNeighbor   = 5; {指定最臨近插值法. }
InterpolationModeHighQualityBilinear = 6; {指定高質量的雙線性插值法. 執行預篩選以確保高質量
                         的收縮. }
InterpolationModeHighQualityBicubic = 7; {指定高質量的雙三次插值法. 執行預篩選以確保高質量
                         的收縮. 此模式可產生質量最高的轉換圖像. }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved