2017-04-25 7 views
0

以下の関数では、WriteableBitmap.PixelBufferプロパティにアクセスしようとして問題が発生しています。私は取得していますメッセージは次のとおりです。'using'ステートメントが無視されています

'WriteableBitmap' does not contain a definition for 'PixelBuffer' and no extension method 'PixelBuffer' accepting a first argument of type 'WriteableBitmap' could be found (are you missing a using directive or an assembly reference?) 

私は

using System.Runtime.InteropServices.WindowsRuntime; 

を含める必要がある他の場所を読みました。しかし、私はこれが含ま使用した場合、何も私のコードでは変化しません。私の解決策の参考資料を見ると、System.Runtime.InteropServicesのようなものは見当たりません。これはWriteableBitmapのPixelBufferにアクセスしようとしている他の人たちの解決策であるように思えます。

private WriteableBitmap ChangeBrightness(WriteableBitmap source, byte change_value) 
    { 
     WriteableBitmap dest = new WriteableBitmap(source); 

     byte[] color = new byte[4]; 

     using (Stream s = source.PixelBuffer.AsStream()) 
     { 
      using (Stream d = dest.PixelBuffer.AsStream()) 
      { 
       // read the pixel color 
       while (s.Read(color, 0, 4) > 0) 
       { 
        // color[0] = b 
        // color[1] = g 
        // color[2] = r 
        // color[3] = a 

        // do the adding algo per byte (skip the alpha) 
        for (int i = 0; i < 4; i++) 
        { 
         if ((int)color[i] + change_value > 255) color[i] = 255; else color[i] = (byte)(color[i] + change_value); 
        } 

        // write the new pixel color 
        d.Write(color, 0, 4); 
       } 
      } 
     } 

     // return the new bitmap 
     return dest; 
    } 
+0

コードのどの部分が機能しませんか。 'WriteableBitmap'が認識されないか、何ですか? – MrZander

+0

'PixelBuffer'は[' Windows.UI.Xaml.Media.Imaging.WriteableBitmap'](https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml)のメンバーであるようです。 media.imaging.writeablebitmap#Windows_UI_Xaml_Media_Imaging_WriteableBitmap_PixelBuffer)、間違ったものを使用しましたか? – DavidG

+2

http://stackoverflow.com/questions/20478467/stream-stream-writeablebitmap-pixelbuffer-asstream-missingこれは関連性が高いようですが、特にアセンブリ/名前空間に関する質問のコメント – MrZander

答えて

1

あなたは、パッケージが属するアセンブリを参照していることを確認します:

System.Runtime.WindowsRuntimeアセンブリ

+0

私が行ったときにアセンブリが見つかりませんでした参照を追加する。私は別の方法で私の問題を解決した。ありがとう – Ken

-1

あなたはプライベートとしてこのメ​​ソッドを宣言しました。メソッドにアクセスしようとしているときに、アクセス違反はないと確信していますか?また、このクラスを含むプロジェクトを右クリックしてソリューションエクスプローラーでプロジェクト参照を確認し、System.Runtime.InteropServices.WindowsRuntimeの正しい参照とアセンブリが読み込まれていることを確認します。その他の必要なアセンブリが含まれます。

0

私は、他の方法で私の元の問題を解決しようとしました。画像の明るさを調整するには、代わりにこの機能を使用しました。

public ImageSource AdjustBrightness(BitmapImage Image, int Value, int mod) 
    { 
     Bitmap TempBitmap = BitmapImage2Bitmap(Image); 

     Bitmap NewBitmap = new Bitmap(TempBitmap.Width, TempBitmap.Height); 

     Graphics NewGraphics = Graphics.FromImage(NewBitmap); 

     float FinalValue = (float)Value/255.0f; 

     float[][] FloatColorMatrix ={ 

       new float[] {1, 0, 0, 0, 0}, 

       new float[] {0, 1, 0, 0, 0}, 

       new float[] {0, 0, 1, 0, 0}, 

       new float[] {0, 0, 0, 1, 0}, 

       new float[] {mod * FinalValue, mod * FinalValue, mod * FinalValue, 1, 1} 
      }; 

     ColorMatrix NewColorMatrix = new ColorMatrix(FloatColorMatrix); 

     ImageAttributes Attributes = new ImageAttributes(); 

     Attributes.SetColorMatrix(NewColorMatrix); 

     NewGraphics.DrawImage(TempBitmap, new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, GraphicsUnit.Pixel, Attributes); 

     Attributes.Dispose(); 

     NewGraphics.Dispose(); 

     return Bitmap2BitmapImage(NewBitmap); 
    } 
関連する問題