mysql img格式缩放,再学 GDI+[89]: TGPImage(9) - 图像缩放时的质量(算法)

本例效果图:

7ba8f9beb5512f8dce942b484b167b4f.gif

代码文件:

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; {指定高质量的双三次插值法. 执行预筛选以确保高质量

的收缩. 此模式可产生质量最高的转换图像. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值