我想在c#中裁剪图像。正如在大多数照片编辑软件中,我想使用可以通过鼠标调整大小和重新定位的矩形框。另外,我想知道如何突出裁剪区域,如this photo所示。使用矩形裁剪图片
Q
使用矩形裁剪图片
1
A
回答
0
选择框的外部似乎有一个黑色的图像放置在它的约30%的alpha。为此,您只需将内容区域外的每个像素都绘制成一个黑色像素,并在其上面绘制一个30%的alpha值。这会产生所需的暗淡效果。
至于如何获得一个矩形在C#中动态分页。
+0
感谢Nick Beradi寻求帮助。问题是,如果我一个接一个像素地工作,那就花很多时间。有没有像颜色矩阵的快速方式? – qulzam 2009-08-03 01:27:48
0
0
您的图像链接不再可用。
因此,假设在一个面板中你有你的图片框与图片裁剪。
首先,你需要创建事件处理程序的鼠标操作就能画出您希望裁剪矩形区域:
private void picBox_MouseDown(object sender, MouseEventArgs e)
{
Cursor = Cursors.Default;
if (Makeselection)
{
try
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
Cursor = Cursors.Cross;
cropX = e.X;
cropY = e.Y;
cropPen = new Pen(Color.Crimson, 1);
cropPen.DashStyle = DashStyle.Solid;
}
picBox.Refresh();
}
catch (Exception ex)
{
}
}
}
private void picBox_MouseUp(object sender, MouseEventArgs e)
{
if (Makeselection)
{
Cursor = Cursors.Default;
}
}
private void picBox_MouseMove(object sender, MouseEventArgs e)
{
Cursor = Cursors.Default;
if (Makeselection)
{
picBox.Cursor = Cursors.Cross;
try
{
if (picBox.Image == null)
return;
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
picBox.Refresh();
cropWidth = e.X - cropX;
cropHeight = e.Y - cropY;
picBox.CreateGraphics().DrawRectangle(cropPen, cropX, cropY, cropWidth, cropHeight);
}
}
catch (Exception ex)
{
}
}
}
private void picBox_MouseLeave(object sender, EventArgs e)
{
tabControl.Focus();
}
private void picBox_MouseEnter(object sender, EventArgs e)
{
picBox.Focus();
}
现在,自带的按钮点击功能裁剪图像:
private void btnCrop_Click_1(object sender, EventArgs e)
{
Cursor = Cursors.Default;
try
{
if (cropWidth < 1)
{
return;
}
Rectangle rect = new Rectangle(cropX, cropY, cropWidth, cropHeight);
//First we define a rectangle with the help of already calculated points
Bitmap OriginalImage = new Bitmap(picBoxScreenshot.Image, picBoxScreenshot.Width, picBoxScreenshot.Height);
//Original image
Bitmap _img = new Bitmap(cropWidth, cropHeight);
// for cropinfo image
Graphics g = Graphics.FromImage(_img);
// create graphics
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
//set image attributes
g.DrawImage(OriginalImage, 0, 0, rect, GraphicsUnit.Pixel);
picBox.Image = _img;
picBox.Width = _img.Width;
picBox.Height = _img.Height;
PictureBoxLocation();
cropWidth = 0;
}
catch (Exception ex){}
}
private void PictureBoxLocation()
{
int _x = 0;
int _y = 0;
if (panel1.Width > picBox.Width)
{
_x = (panel1.Width - picBox.Width)/2;
}
if (panel1.Height > picBox.Height)
{
_y = (panel1.Height - picBox.Height)/2;
}
picBox.Location = new Point(_x, _y);
picBox.Refresh();
}
相关问题
- 1. OpenCV裁剪矩形
- 2. CSS圆形裁剪矩形图像
- 3. 使用OpenCV裁剪最大的矩形
- 4. 在JavaScript中剪裁矩形
- 5. 元文件剪裁矩形
- 6. 自定义矩形的图像裁剪
- 7. 如何使用CSS将矩形图像裁剪为正方形?
- 8. 使用非矩形形状在flex中裁剪图像
- 9. 裁剪图片,从X,Y获取矩形?
- 10. 使用矩形几何不拉伸的图像剪裁
- 11. 使用c从图像裁剪十字矩形#
- 12. C#&WPF - 通过使用矩形对象裁剪图像
- 13. 使用选定区域的矩形框来裁剪图像?
- 14. 使用imagemagick从图像裁剪矩形区域
- 15. 裁剪矩阵
- 16. 裁剪缩略图图片
- 17. C#裁剪图片使用坐标
- 18. 使用JCrop裁剪多张图片
- 19. 使用GKImagePicker剪裁照片
- 20. 如何从矩形叠加裁剪uiimageView?
- 21. 在opencv中裁剪矩形区域
- 22. com.android.camera.action.CROP调整裁剪矩形的大小
- 23. 从pickerView中裁剪图片
- 24. CSS3中心裁剪图片
- 25. 错误地裁剪图片
- 26. java的图片剪裁
- 27. 裁剪大背景图片
- 28. C#:GDI +图片裁剪
- 29. 裁剪图片目标C
- 30. 圆形裁剪图像
您在这里找什么?从较大的图像裁剪一部分的实际方法?或者您可以通过一种方式显示您的剪裁选择,就像您链接的图片一样? – peSHIr 2009-08-02 20:31:02
我已经对裁剪有一些想法。我想帮助您展示剪裁选择的方式。我也移动裁剪选择。 – qulzam 2009-08-03 01:25:13