2012-11-17 3 views
0

나는 tiff 이미지를자를 수있는 루틴을 찾고 있었지만 얻었지만 많은 오류가 발생합니다. 다음은 루틴입니다.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); 
} 
} 
} 

컴파일 할 때 오류가 발생합니다. 나는 구글을 검색하는 많은 어셈블리에 대한 참조를 추가하려했지만 그것을 해결할 수 없었다. 이 URL에서이 코드를 받았습니다.

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

나는 조언을 구하고 있습니다.

+0

확실한 오류를 추가하는 데 도움이됩니다 .... – rene

+0

또한 TIFF 이미지 자체 (색상, 다중 프레임 등)에 대한 자세한 정보를 제공해주십시오. GDI + /. NET은 특정 종류의 TIFF 파일에 문제가 있습니다. – HackedByChinese

답변

0

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; 
} 
관련 문제