2012-11-28 155 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更新我! –