Click here to Skip to main content
15,911,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I need the code to crop the tiff(Tagged Image File format) image in my application
using the namespace System.Drawing.

I googled for it, but not getting the proper idea.

Please any one give the code to crop the tiff image.


Regards,
Raj
Posted
Updated 19-May-11 18:32pm
v3

Try:
Image i = Image.FromFile(@"F:\Temp\MyPic.tif");
Image cropped = new Bitmap(200, 200);
Graphics g = Graphics.FromImage(cropped);
Rectangle dest = new Rectangle(new Point(0, 0), cropped.Size);
Rectangle source = new Rectangle(new Point(100,100), cropped.Size);
g.DrawImage(i, dest, source, GraphicsUnit.Pixel);
g.Dispose();
 
Share this answer
 
Comments
Raj.rcr 19-May-11 5:52am    
Its working, but can u plz tell me how to display the cropped image using javascript?
OriginalGriff 19-May-11 7:05am    
How are you showing the image in your web page?
Raj.rcr 19-May-11 7:13am    
I am using the ScriptManager to display the image as below:

string PDFfileName = string.Empty;
PDFfileName = txtImgPathHid.Text.ToString();
int MyRandomNumber = RandomNo.Next();
ScriptManager.RegisterStartupScript(this, typeof(string), MyRandomNumber.ToString(), "javascript:setsrc('" + PDFfileName + "');", true);
Raj.rcr 19-May-11 8:20am    
I am not getting, Can u plz tell me how to save the cropped tiff image and then display it on the webpage?
Go through this discussion: Cropping a Image Using C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900