Posted By

caringprogrammer on 02/04/12


Tagged

c# tiffcropping


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Priestd09


How to read tiff in C# and crop it


 / Published in: C#
 

URL: http://caringprogrammer.blogspot.com/

Sample code to read tiff in C# and cropp it

  1. Bitmap comments = null;
  2. string input = "somepath";
  3. // Open a Stream and decode a TIFF image
  4. using (Stream imageStreamSource = new FileStream(input, FileMode.Open, FileAccess.Read, FileShare.Read))
  5. {
  6. TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
  7.  
  8. BitmapSource bitmapSource = decoder.Frames[0];
  9. using (Bitmap b = BitmapFromSource(bitmapSource))
  10. {
  11. Rectangle cropRect = new Rectangle(169, 1092, 567, 200);
  12. comments = new Bitmap(cropRect.Width, cropRect.Height);
  13.  
  14. //first cropping
  15. using (Graphics g = Graphics.FromImage(comments))
  16. {
  17. g.DrawImage(b, new Rectangle(0, 0, comments.Width, comments.Height),
  18. cropRect,
  19. GraphicsUnit.Pixel);
  20. }
  21. }
  22. }

Report this snippet  

You need to login to post a comment.