作者andy910389 (*微凉的你*)
看板C_Sharp
标题[问题] 放大镜程式的一个小问题
时间Tue Mar 30 15:01:42 2010
就是我刚看到书上对於圆形放大镜程式有一段我一直看不懂
因为她说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)