首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

Delphi GDI+ 學習筆記 (26):TGPImage 影像載入顯示與縮放插值

     編輯:Delphi

通用影像容器:JPG/PNG/BMP/GIF/TIFF/EMF 統一介面

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);

平行四邊形變換 (3 點控制)


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);

InterpolationMode 對照表

Delphi 常數微軟名稱品質/速度適用縮放範圍
InterpolationModeNearestNeighborNearestNeighbor低/極快任意
InterpolationModeBilinearBilinear中/快> 50%
InterpolationModeBicubicBicubic高/中> 25%
InterpolationModeHighQualityBilinearHighQualityBilinear高/中任意 (預篩選)
InterpolationModeHighQualityBicubicHighQualityBicubic最高/慢任意 (預篩選)
InterpolationModeDefaultDefault系統預設-
InterpolationModeHighHigh高-
InterpolationModeLowLow低-
InterpolationModeInvalidInvalid無效-

建議:UI 縮圖用 HighQualityBilinear,列印/匯出用 HighQualityBicubic,即時預覽用 NearestNeighbor。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved