就是我剛看到書上對於圓形放大鏡程式有一段我一直看不懂
因為她說drawimage()只支援矩形區域繪出到一個矩形區域
但是如果今天要換成圓形的放大鏡就要不同的寫法
以下是主要程式碼 但紅色那一行我研究了一天還是不懂...
為什麼她要在初始環境就先把圖繪出來 而且還是兩倍大小的圖?
但是明明呈現出來的就是paint()裡面寫的原圖大小而以阿
到底她紅色那段的目的在哪呀?
而且我有嘗試把paint()裡的程式碼助解掉...結果就沒有顯示圖
只有顯示圖的區域大小而以...可是紅色那一段不就是應該匯出兩倍大小的圖形才對嗎???
public Form1()
{
InitializeComponent();
img = Properties.Resources.Beauty; // 影像從資源載入
this.ClientSize = new Size(img.Width, img.Height);// 調整視窗客戶
區寬高
imgDouble = new Bitmap(img.Width * 2, img.Height*2); // 新增點陣
圖物件
Graphics G = Graphics.FromImage(imgDouble); // 由點陣圖物件產生畫
布
Rectangle rectDest = new Rectangle(0,0,imgDouble.Width,
imgDouble.Height);
Rectangle rectSrc = new Rectangle(0,0,img.Width, img.Height);
G.DrawImage(img, rectDest, rectSrc, GraphicsUnit.Pixel); // 放大兩
倍
texBrush = new TextureBrush(imgDouble); // 兩倍影像的塗刷
}
// 表單重畫事件
private void Form1_Paint(object sender, PaintEventArgs e)
{
if (img != null)
{
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
e.Graphics.DrawImage(img, 0, 00, img.Width, img.Height); // 呈
現原圖
Rectangle rectDest = new Rectangle(mousePos.X-D,
mousePos.Y-D, 2*D, 2*D);
texBrush.ResetTransform(); // 塗刷的轉換矩陣 = 單位矩陣
texBrush.TranslateTransform(-mousePos.X, -mousePos.Y); // 塗刷
對齊 滑鼠位置
e.Graphics.FillEllipse(texBrush, rectDest); // 使用影像塗刷 繪
出圓形
e.Graphics.DrawEllipse(Pens.Black, rectDest); // 放大鏡外框
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.60.253.80
※ 編輯: andy910389 來自: 61.60.253.80 (03/30 15:07)