日期:2014-05-17 浏览次数:20963 次
/// <summary>
/// 放大缩小图片的局部
/// </summary>
/// <param name="g">缩放后的图像画布</param>
/// <param name="Magnification">放大倍率</param>
/// <param name="MouseX">鼠标位置</param>
/// <param name="MouseY"></param>
/// <param name="SourceImage">放大的源图象</param>
/// <param name="ContainerRect">存放放大后图像的容器的大小</param>
void Magnifier(Graphics g,int Magnification, int MouseX, int MouseY, Image SourceImage, Rectangle ContainerRect)
{
//计算在原图上截取图片的范围
int w = ContainerRect.Width / Magnification;
int h = ContainerRect.Height / Magnification;
int x = MouseX - w / 2;
int y = MouseY - w / 2;
if (x>SourceImage.Width)
{
x = SourceImage.Width - w;
}
else if (x<0)
{
x = 0;
}
if (y>SourceImage.Height )
{
y = SourceImage.Height - h;
}
else if (y<0)
{
y = 0;
}
//截取原图的x.y.w.h范围,并缩放适合ContainerRect的大小,达到放大缩小的效果
g.Dra