//顯示圖像var
//按標准的高度與寬度顯示圖像
g: TGPGraphics;
img: TGPImage;
begin
g := TGPGraphics.Create(Self.Canvas.Handle);
img := TGPImage.Create('c:tempx.jpg');
g.DrawImage(img,10,10); {參數2、3是坐標}
img.Free;
g.Free;
end;var
//按指定高度與寬度顯示圖像
g: TGPGraphics;
img: TGPImage;
begin
g := TGPGraphics.Create(Canvas.Handle);
img := TGPImage.Create('c:tempx.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);
img := TGPImage.Create('c:tempx.jpg');
g.DrawImage(img, 10, 10, 100, 200);
img.Free;
g.Free;
end;var
//圖片平行四邊形變換
g : TGPGraphics;
img, imgSmall: TGPImage;
begin
g := TGPGraphics.Create(Canvas.Handle);
img:= TGPImage.Create('c:tempx.jpg');
imgSmall := img.GetThumbnailImage(48, 60, nil, nil);
g.DrawImage(imgSmall, 10, 10, imgSmall.GetWidth, imgSmall.GetHeight);
img.Free;
imgSmall.Free;
g.Free;
end;var
//圖像縮放時的算法比對
g: TGPGraphics;
img: TGPImage;
const
pts: array[0..2] of TGPPoint = ((x:300; y:120),
(x:210; y:200),
(x:350; y:230));
begin
g := TGPGraphics.Create(Canvas.Handle);
img:= TGPImage.Create('c:tempx.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);
img:= TGPImage.Create('c:tempx.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, 250, 0.6*w, 0.6*h), 0, 0, w, h, UnitPixel);
g.SetInterpolationMode(InterpolationModeHighQualityBilinear);
g.DrawImage(img, MakeRect(150, 250, 0.6*w, 0.6*h), 0, 0, w, h, UnitPixel);
g.SetInterpolationMode(InterpolationModeHighQualityBicubic);
g.DrawImage(img, MakeRect(290, 250, 0.6*w, 0.6*h), 0, 0, w, h, UnitPixel);
img.Free;
g.Free;
end;