图像框选放大和缩小(在线等) 如何实现框选图片的某个部位然后放大或者缩小?高手指点,急用 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 框选private GraphicsPath gp = new GraphicsPath();MouseMove: preview.Refresh(); gp.Reset(); gp.AddRectangle(new Rectangle(p0.X, p0.Y, Math.Abs(p0.X - p1.X), Math.Abs(p0.Y - p1.Y))); Graphics g = preview.CreateGraphics(); Pen pen = new Pen(Color.Red, 1.0f); g.DrawPath(pen, gp); g.Dispose();MouseDown: preview.Refresh(); gp.Reset();需要注意处理起始点和终止点的位置问题(比如,用户从右下拖到左上)框选好以后你可以用Graphics类的DrawImage得到框选好的图像。同样还是DrawImage实现放大缩小。//剪裁 public static Bitmap KiCut(Bitmap b, int StartX, int StartY, int iWidth, int iHeight) { if (b == null) { return null; } int w = b.Width; int h = b.Height; if (StartX >= w || StartY >= h) { return null; } if (StartX + iWidth > w) { iWidth = w - StartX; } if (StartY + iHeight > h) { iHeight = h - StartY; } Bitmap bmpOut = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmpOut); g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel); g.Dispose(); return bmpOut; }//重设大小 public static Bitmap KiResizeImage(Bitmap bmp, int newW, int newH) { try { Bitmap b = new Bitmap(newW, newH); Graphics g = Graphics.FromImage(b); //强制用效果最好的插值算法 g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.DrawImage(bmp, new Rectangle(0, 0, newW, newH), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel); g.Dispose(); return b; } catch { return null; } }需要的话,最后再把得到的Bitmap重新画到PictureBox里。 picturebox控件,acdsee控件,图片控件;用C#开发的图片控件,功能类似acdsee;支持各种图片的浏览,放大,缩小,平移等功能;源代码参考:http://shop.paipai.com/359073000 不通过安装Oracle客户端,C#连接Oracle数据库如何实现? 调用不同资源文件 用户控件中的 static 函数怎么引用? 请教高手水晶报表问题: 如何创建一个圆角窗体。 一个treeview控件的问题(winfrom) 请问当上万条数据绑定到一个下拉菜单时候 怎么样提高显示速度? nhibernate 一对多问题 EF映射的一个问题 cefsharp winform 代理问题 c#如何实现图片的局部放大? 求教:怎么样在C#中控制图片的放大与放小..小弟请教..
private GraphicsPath gp = new GraphicsPath();MouseMove: preview.Refresh();
gp.Reset();
gp.AddRectangle(new Rectangle(p0.X, p0.Y, Math.Abs(p0.X - p1.X), Math.Abs(p0.Y - p1.Y)));
Graphics g = preview.CreateGraphics();
Pen pen = new Pen(Color.Red, 1.0f);
g.DrawPath(pen, gp);
g.Dispose();
MouseDown:
preview.Refresh();
gp.Reset();需要注意处理起始点和终止点的位置问题(比如,用户从右下拖到左上)
框选好以后你可以用Graphics类的DrawImage得到框选好的图像。同样还是DrawImage实现放大缩小。//剪裁
public static Bitmap KiCut(Bitmap b, int StartX, int StartY, int iWidth, int iHeight)
{
if (b == null)
{
return null;
} int w = b.Width;
int h = b.Height; if (StartX >= w || StartY >= h)
{
return null;
} if (StartX + iWidth > w)
{
iWidth = w - StartX;
} if (StartY + iHeight > h)
{
iHeight = h - StartY;
} Bitmap bmpOut = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmpOut);
g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);
g.Dispose(); return bmpOut;
}
//重设大小
public static Bitmap KiResizeImage(Bitmap bmp, int newW, int newH)
{
try
{
Bitmap b = new Bitmap(newW, newH);
Graphics g = Graphics.FromImage(b); //强制用效果最好的插值算法
g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.DrawImage(bmp, new Rectangle(0, 0, newW, newH), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
g.Dispose(); return b;
}
catch
{
return null;
}
}
需要的话,最后再把得到的Bitmap重新画到PictureBox里。
用C#开发的图片控件,功能类似acdsee;
支持各种图片的浏览,放大,缩小,平移等功能;
源代码参考:http://shop.paipai.com/359073000