2012-05-03 8 views
1

実行時に単純なtiffイメージを生成しようとしています。このイメージは、白い背景とリモートサーバーからダウンロードされたイメージで構成されています。実行時にWPFでtiffイメージを作成する

ここで私はその目標に到達するために書かれたコードです:

 const string url = "http://localhost/barcode.gif"; 

     var size = new Size(794, 1123); 
     var drawingVisual = new DrawingVisual(); 

     using (var drawingContext = drawingVisual.RenderOpen()) 
     { 
      drawingContext.DrawRectangle(new SolidColorBrush(Colors.White), null, new Rect(size)); 

      var image = new BitmapImage(new Uri(url)); 
      drawingContext.DrawImage(image, new Rect(0, 0, 180, 120)); 
     } 

     var targetBitmap = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Default); 
     targetBitmap.Render(drawingVisual); 

     var convertedBitmap = new FormatConvertedBitmap(targetBitmap, PixelFormats.BlackWhite, null, 0); 

     var encoder = new TiffBitmapEncoder(); 
     encoder.Frames.Add(BitmapFrame.Create(convertedBitmap)); 

     using (var fs = new FileStream("out.tif", FileMode.Create)) 
     { 
      encoder.Save(fs); 
     } 

コードが動作すると、「out.tif」ファイルを生成しますが。しかし、出力ファイルは、白いバックグラウンドを持ち、リモートサーバーから受信したイメージはありません。

何が問題なのですか?私は、さまざまな方法で次のコードを試しましたが、毎回運がない。

答えて

0

私はFormatConvertedBitmapクラスに関するこの読書を見つけました。多分それにショットを与える

 FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap(); 

     // BitmapSource objects like FormatConvertedBitmap can only have their properties 
     // changed within a BeginInit/EndInit block. 
     newFormatedBitmapSource.BeginInit(); 

     // Use the BitmapSource object defined above as the source for this new 
     // BitmapSource (chain the BitmapSource objects together). 
     newFormatedBitmapSource.Source = targetBitmap; 

     // Set the new format to BlackWhite. 
     newFormatedBitmapSource.DestinationFormat = PixelFormats.BlackWhite; 
     newFormatedBitmapSource.EndInit(); 
関連する問題