簡體   English   中英

縮放圖像二維變換矩陣

[英]Scaling an image 2d transformation matrix

我希望將圖像縮放到必須保持縱橫比的某個寬度(例如imgContainerWidth)。 我采用了二維變換矩陣方法。

矩陣:

 | a  c e |
 | b  d f |
 | 0  0 1 | // This bottom row is constant.

 a = scales the element horizontally
 b = skew the the element horizontally
 c = skew the the drawing vertically
 d = scales the drawing vertically
 e = moves the the element horizontally
 f = moves the the element vertically

 matrix(a, b, c, d, e, f);

 .....


 scaleX = imgContainerWidth / imgWidth; 
 matrix[0] = scaleX; // scale X
 matrix[3] = scaleX; // scale Y

 .....

這樣可以很好地縮放圖像。 但是,圖像的頂部不可見,需要向下移動。 我需要沿y軸平移圖像。 我的問題是如何計算該值,以便圖像的頂部可見。

干杯。

我設法弄清楚了這一點:

 scaleX = imgContainerWidth / imgWidth;
 newHeight = imgHeight * scaleX;
 translateY = newHeight - imgHeight;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM