2012-11-28 51 views
1

我正在使用Jcrop尝试裁剪和图像并保存它。如何裁剪图像

http://deepliquid.com/content/Jcrop.html 

出于这种演示的是一个我在执行:一旦这些submited

http://deepliquid.com/projects/Jcrop/demos.php?demo=handler 

它给了我几个坐标X1,Y1,X2,Y2,X,Y

我如何使用它们来裁剪图像?

我已经看过http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing

这是最好的办法吗?它只是利用X,Y,W和H

回答

2

使用Graphics.DrawImage是一个更好的主意来修剪长在C#

Rectangle cropRect = new Rectangle(...); 
Bitmap src = Image.FromFile(fileName) as Bitmap; 
Bitmap target = new Bitmap(cropRect.Width, cropRect.Height); 

using(Graphics g = Graphics.FromImage(target)) 
{ 
    g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), 
       cropRect,       
       GraphicsUnit.Pixel); 
} 

图像从源Thread

+0

什么在新的矩形?不知道这是假设如何工作 – Beginner

+0

@Rahul Tripathi原谅我回答你提供已经在stackoverflow答案http://stackoverflow.com/questions/734930/how-to-crop-an-image-using-c通过“Daniel LeCheminant“至少提到他的名字是好的。 – MMK

+0

@MMK: - 我真的很抱歉。我刚刚使用源代码线程更新了我的答案。希望这是好的?和thanx更新我! –