2010-12-23 8 views
6

Bir resmi döndürdüğümde .Net, tiff kodlamasını değiştirir. CCITT Faks 4'ü (Grup 4 Faks kodlaması) saklayabilmem ve LZW'ye geçmemenin bir yolu var mı? İşte bir görüntüyü diskte nasıl döndürüyorum..Net Image.Save, CTTIT Faks 4'ten LZW'ye geçişi değiştirir

System.Drawing.Image img = System.Drawing.Image.FromFile(input); 
//rotate the picture by 90 degrees 
img.RotateFlip(RotateFlipType.Rotate90FlipNone); 
img.Save(input, System.Drawing.Imaging.ImageFormat.Tiff); 

sayesinde Brian

Güncelleme: İşte aşağıda bağlantı makalelere dayanarak kod. Kodu tamamlayıcılar için buraya eklemek istedim. Ayrıca, yatay çözünürlüğü ayarlıyorum çünkü bitmapler varsayılanı 96 DPI'dır.

//create an object that we can use to examine an image file 
System.Drawing.Image img = System.Drawing.Image.FromFile(input); 

//rotate the picture by 90 degrees 
img.RotateFlip(RotateFlipType.Rotate90FlipNone); 

// load into a bitmap to save with proper compression 
Bitmap myBitmap = new Bitmap(img); 
myBitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution); 

// get the tiff codec info 
ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/tiff"); 

// Create an Encoder object based on the GUID for the Compression parameter category 
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Compression; 

// create encode parameters 
EncoderParameters myEncoderParameters = new EncoderParameters(1); 
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT4); 
myEncoderParameters.Param[0] = myEncoderParameter; 

// save as a tiff 
myBitmap.Save(input, myImageCodecInfo, myEncoderParameters); 

// get encoder info for specified mime type 
private static ImageCodecInfo GetEncoderInfo(String mimeType) 
{ 
    int j; 
    ImageCodecInfo[] encoders; 
    encoders = ImageCodecInfo.GetImageEncoders(); 
    for (j = 0; j < encoders.Length; ++j) 
    { 
     if (encoders[j].MimeType == mimeType) 
      return encoders[j]; 
    } 
    return null; 
} 

cevap

6

Görüntü sınıfı size gerekli taneli denetimleri vermeyecektir.

Bunu yapmak için, bir Bitmap okumalı, bir TIFF enkoder oluşturmalı, sıkıştırma türü için parametreyi ayarlamalısınız, daha sonra Bitmap nesnesinin görüntüyü o kodek ve parametreyi kullanarak kaydetmesini sağlamanız gerekir.

http://msdn.microsoft.com/en-us/library/system.drawing.imaging.encoder.compression.aspx

şu anda benim Mac, VS açık gerekmez:

İşte size doğru yönde gitmelidir bir örnek. işleri

http://social.msdn.microsoft.com/Forums/en/windowswic/thread/e05f4bc2-1f5c-4a10-bd73-86a676dec554

+0

Teşekkür:

İşte Detaylar. DPI'yi 300'den 96'ya değiştiriyor. Herhangi biri nasıl ayarlanacağını biliyor mu? – BrianK

+0

Sanırım görüntü sınıfı bunu destekliyor (en azından benim için çalışıyor). Bu yüzden fazladan bitmap'e sahip olmanıza gerek yoktur ve ek bir bonus olarak, çözünürlüğü ortadan kaldırmaya gerek yoktur. – user12861

+0

BrianK: Bitmap.SetResolution() bunu yapacak, (bu muhtemelen 2 yıl sonra size yardımcı olmayacaktır!) – user20493