简体   繁体   English

如何在asp.net中裁剪tiff图像

[英]How to crop a tiff image in asp.net

I was looking for a routine by which I can crop tiff image and I got it but it gives many error. 我一直在寻找一个常规由我可以裁剪的TIFF图像,我得到了它,但它提供了许多错误。 Here is the routine: 这是例程:

Bitmap comments = null;
string input = "somepath";
// Open a Stream and decode a TIFF image
using (Stream imageStreamSource = new FileStream(input, FileMode.Open, FileAccess.Read, FileShare.Read))
{
TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

BitmapSource bitmapSource = decoder.Frames[0];
using (Bitmap b = BitmapFromSource(bitmapSource))
{
Rectangle cropRect = new Rectangle(169, 1092, 567, 200);
comments = new Bitmap(cropRect.Width, cropRect.Height);

//first cropping
using (Graphics g = Graphics.FromImage(comments))
{
g.DrawImage(b, new Rectangle(0, 0, comments.Width, comments.Height),
cropRect,
GraphicsUnit.Pixel);
}
}
}

When I try to compile it, I get an error. 当我尝试编译它时,出现错误。 I tried adding references to many assemblies searching google but couldn't resolve it. 我尝试添加对搜索google的许多程序集的引用,但无法解决。 I got this code from this url: 我从以下网址获得此代码:

http://snipplr.com/view/63053/

I am looking for advice. 我正在寻找建议。

TiffBitmapDecoder class is from Presentation.Core in another words it is from WPF. TiffBitmapDecoder类来自Presentation.Core ,换句话说,它来自WPF。

BitmapFromSource isn't method of any .net framework class. BitmapFromSource不是任何.net框架类的方法。 You can convert BitmapSource to Bitmap using this code. 您可以使用此代码将BitmapSource转换为Bitmap。

private Bitmap BitmapFromSource(BitmapSource bitmapsource)
 {
     Bitmap bitmap;
     using (MemoryStream outStream = new MemoryStream())
     {
       BitmapEncoder encoder = new BmpBitmapEncoder();
       encoder.Frames.Add(BitmapFrame.Create(bitmapsource));
       encoder.Save(outStream);
       bitmap = new Bitmap(outStream);
     }
     return bitmap;
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM