我想在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