簡體   English   中英

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

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

我一直在尋找一個常規由我可以裁剪的TIFF圖像,我得到了它,但它提供了許多錯誤。 這是例程:

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);
}
}
}

當我嘗試編譯它時,出現錯誤。 我嘗試添加對搜索google的許多程序集的引用,但無法解決。 我從以下網址獲得此代碼:

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

我正在尋找建議。

TiffBitmapDecoder類來自Presentation.Core ,換句話說,它來自WPF。

BitmapFromSource不是任何.net框架類的方法。 您可以使用此代碼將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