//显示图像
var
g:TGPGraphics;
img:TGPImage;
begin
g:=TGPGraphics
.
Create(Canvas
.
Handle);
g
.
Clear(aclWhite);
img:=TGPImage
.
Create(
'd:\mm.jpg'
);
g
.
DrawImage(img,
10
,
10
);
{参数2、3是坐标}
img
.
Free;
g
.
Free;
end
;
|
//按标准的高度与宽度显示图像
var
g:TGPGraphics;
img:TGPImage;
begin
g:=TGPGraphics
.
Create(Canvas
.
Handle);
g
.
Clear(aclWhite);
img:=TGPImage
.
Create(
'd:\mm.jpg'
);
g
.
DrawImage(img,
10
,
10
,img
.
GetWidth,img
.
GetHeight);
img
.
Free;
g
.
Free;
end
;
|
//按指定高度与宽度显示图像
var
g:TGPGraphics;
img:TGPImage;
begin
g:=TGPGraphics
.
Create(Canvas
.
Handle);
g
.
Clear(aclWhite);
img:=TGPImage
.
Create(
'd:\mm.jpg'
);
g
.
DrawImage(img,
10
,
10
,
200
,
100
);
img
.
Free;
g
.
Free;
end
;
|
//略缩图
var
g:TGPGraphics;
smallimg,img:TGPImage;
begin
g:=TGPGraphics
.
Create(Canvas
.
Handle);
g
.
Clear(aclWhite);
img:=TGPImage
.
Create(
'd:\mm.jpg'
);
smallimg:=img
.
GetThumbnailImage(
48
,
60
,
nil
,
nil
);
g
.
DrawImage(smallimg,
10
,
10
,smallimg
.
GetWidth,smallimg
.
GetHeight);
smallimg
.
Free;
img
.
Free;
g
.
Free;
end
;
|
//图片平行四边形变换
var
g:TGPGraphics;
img:TGPImage;
const
pts:
array
[
0..2
]
of
TGPPoint = ((x:
380
;y:
20
),
(x:
280
;y:
70
),
(x:
400
;y:
200
));
begin
g:=TGPGraphics
.
Create(Canvas
.
Handle);
g
.
Clear(aclWhite);
img:=TGPImage
.
Create(
'd:\mm.jpg'
);
g
.
DrawImage(img,
0
,
0
);
{这是原始图片}
g
.
DrawImage(img,PGPPoint(@pts),
3
);
{反复测试后, 感悟如下:
1、只需要 3 个点来控制图片, 不能多或少.
2、点 1 控制右上角; 点 2 控制左上角; 点 3 控制右下角.
3、因为是平行四边形, 所以剩下的左下角的点(就是右上角的对角点)程序就可以算得出来了.
}
img
.
Free;
g
.
Free;
end
;
|
//图像缩放时的算法比对
var
g:TGPGraphics;
img:TGPImage;
w,h:UINT;
begin
g:=TGPGraphics
.
Create(Canvas
.
Handle);
g
.
Clear(aclWhite);
img:=TGPImage
.
Create(
'd:\mm.jpg'
);
w:=img
.
GetWidth;
h:=img
.
GetHeight;
g
.
DrawImage(img,MakeRect(
10
,
10
,w,h),
0
,
0
,w,h,UnitPixel);
g
.
SetInterpolationMode(InterpolationModeNearestNeighbor);
g
.
DrawImage(img,MakeRect(
10
,
210
,
0.6
*w,
0.6
*h),
0
,
0
,w,h,UnitPixel);
g
.
SetInterpolationMode(InterpolationModeHighQualityBilinear);
g
.
DrawImage(img,MakeRect(
150
,
210
,
0.6
*w,
0.6
*h),
0
,
0
,w,h,UnitPixel);
g
.
SetInterpolationMode(InterpolationModeHighQualityBicubic);
g
.
DrawImage(img,MakeRect(
290
,
210
,
0.6
*w,
0.6
*h),
0
,
0
,w,h,UnitPixel);
img
.
Free;
g
.
Free;
end
;
|
缩放或旋转图像时的算法选项:
Delphi | 微软 | 说明 |
---|---|---|
InterpolationModeBicubic | Bicubic | 指定双三次插值法。不进行预筛选。将图像收缩为原始大小的 25% 以下时,此模式不适用。 |
InterpolationModeBilinear | Bilinear | 指定双线性插值法。不进行预筛选。将图像收缩为原始大小的 50% 以下时,此模式不适用。 |
InterpolationModeDefault | Default | 指定默认模式。 |
InterpolationModeHigh | High | 指定高质量插值法。 |
InterpolationModeHighQualityBicubic | HighQualityBicubic | 指定高质量的双三次插值法。执行预筛选以确保高质量的收缩。此模式可产生质量最高的转换图像。 |
InterpolationModeHighQualityBilinear | HighQualityBilinear | 指定高质量的双线性插值法。执行预筛选以确保高质量的收缩。 |
InterpolationModeInvalid | Invalid | 等效于 QualityMode 枚举的 Invalid 元素。 |
InterpolationModeLow | Low | 指定低质量插值法。 |
InterpolationModeNearestNeighbor | NearestNeighbor | 指定最临近插值法。 |