2012-01-13 7 views
2

画像に変換しようとしているファイルストリームがあります。私は以下のコードを持っていますasp.net c#ファイルストリームを画像に変換する

FileStream imageFile = image["file"] as FileStream; 

画像は画像上の情報を保持している地図です。私が次にやるべきことを私に指示する人もいます。

+0

なぜあなたは 'image'変数名を複製しているの?私はあなたが持っているものがコンパイルされるのか疑問に思います。 – Oded

+3

「イメージに変換する」とはどういう意味ですか - イメージをBitmapインスタンスに変換するか、イメージリクエストに応じてクライアントに提供することを意味しますか? –

+0

イメージがサーバー上にあり、FileStreamを使用してイメージを取得すると、イメージはWebページに表示されます。 – c11ada

答えて

4

Image.FromStreamはストリームを受け取り、画像を返します。ちなみに、Bitmap.FromStreamまたはImage.FromStream、またはこれらの方法のいずれかを使用すると、それらはすべてBitmapを返すので、必要に応じてBitmapからImageにアップキャストすることができます。

1

あなたが次の操作を行うことができます。

 int width = 128; 
     int height = width; 
     int stride = width/8; 
     byte[] pixels = new byte[height * stride]; 

     // Define the image palette 
     BitmapPalette myPalette = BitmapPalettes.Halftone256; 

     // Creates a new empty image with the pre-defined palette 
     BitmapSource image = BitmapSource.Create(
      width, 
      height, 
      96, 
      96, 
      PixelFormats.Indexed1, 
      myPalette, 
      pixels, 
      stride); 

     FileStream stream = new FileStream("new.jpg", FileMode.Create); 
     JpegBitmapEncoder encoder = new JpegBitmapEncoder(); 
     encoder.FlipHorizontal = true; 
     encoder.FlipVertical = false; 
     encoder.QualityLevel = 30; 
     encoder.Rotation = Rotation.Rotate90; 
     encoder.Frames.Add(BitmapFrame.Create(image)); 
     encoder.Save(stream); 
+0

私はコードを忘れました: –

関連する問題