TGPImage 為唯讀影像基底類別,支援多種格式自動偵測。提供 DrawImage 多載:座標、目標矩形、來源矩形、平行四邊形變換、縮略圖、插值模式切換。
// 原始大小
g.DrawImage(img, 10, 10);
// 指定寬高
g.DrawImage(img, 10, 10, 100, 200);
// 1:1 精確大小
g.DrawImage(img, 10, 10, img.GetWidth, img.GetHeight);
imgSmall := img.GetThumbnailImage(48, 60, nil, nil);
g.DrawImage(imgSmall, 10, 10, imgSmall.GetWidth, imgSmall.GetHeight);
const pts: array[0..2] of TGPPoint = ((X:300;Y:120),(X:210;Y:200),(X:350;Y:230));
g.DrawImage(img, PGPPoint(@pts), 3);
// 點1=右上、點2=左上、點3=右下,左下由平行四邊形幾何自動推導
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);
| Delphi 常數 | 微軟名稱 | 品質/速度 | 適用縮放範圍 |
|---|---|---|---|
| InterpolationModeNearestNeighbor | NearestNeighbor | 低/極快 | 任意 |
| InterpolationModeBilinear | Bilinear | 中/快 | > 50% |
| InterpolationModeBicubic | Bicubic | 高/中 | > 25% |
| InterpolationModeHighQualityBilinear | HighQualityBilinear | 高/中 | 任意 (預篩選) |
| InterpolationModeHighQualityBicubic | HighQualityBicubic | 最高/慢 | 任意 (預篩選) |
| InterpolationModeDefault | Default | 系統預設 | - |
| InterpolationModeHigh | High | 高 | - |
| InterpolationModeLow | Low | 低 | - |
| InterpolationModeInvalid | Invalid | 無效 | - |
建議:UI 縮圖用 HighQualityBilinear,列印/匯出用 HighQualityBicubic,即時預覽用 NearestNeighbor。