1

WriteableBitmaps として持っている 2 つの画像をマージしようとしています。各ピクセル値を二乗し、それを他の画像に追加してから、2番目のルートを取得します(値が255を超える場合は+チェック)。WriteableBitmapEx と ForEach() ( Sobel operator & Convolution with WriteableBitmapEx ) (これもかなり遅いようです) を使用してそうすることができなかったので、BitmapDecoder を使用してピクセルを直接操作してみました。残念ながら、エラーが発生するため、Pixelstream を WriteableBitmap に書き戻すことができないようです。

'Windows.Storage.Streams.IBuffer' には 'AsStream' の定義が含まれておらず、最適な拡張メソッド オーバーロード 'System.IO.WindowsRuntimeStreamExtensions.AsStream(Windows.Storage.Streams.IRandomAccessStream)' にはいくつかの無効な引数があります

インスタンス引数: 'Windows.Storage.Streams.IBuffer' から 'Windows.Storage.Streams.IRandomAccessStream' に変換できません

これらの行について

using (Stream stream = bmp.PixelBuffer.AsStream())
{
   await stream.WriteAsync(pixels1, 0, pixels1.Length);
}

これは、WriteableBitmapEx ライブラリによって壊れている可能性がありますか?

さらに、WriteableBitmaps を BitmapDecoders に入れる方法を考えています。このコードは、Win8 コーディング ブックから取得しました。

これまでの私の完全なコードは次のとおりです。

    async Task SobelCombine(BitmapDecoder decoder1, BitmapDecoder decoder2)
    {
        PixelDataProvider provider1 = await decoder1.GetPixelDataAsync(
            BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, new BitmapTransform(),
            ExifOrientationMode.RespectExifOrientation, ColorManagementMode.ColorManageToSRgb);
        byte[] pixels1 = provider1.DetachPixelData();
        PixelDataProvider provider2 = await decoder1.GetPixelDataAsync(
            BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, new BitmapTransform(),
            ExifOrientationMode.RespectExifOrientation, ColorManagementMode.ColorManageToSRgb);
        byte[] pixels2 = provider1.DetachPixelData();



        for (int i = 0; i < pixels1.Length; i += 4){
            pixels1[i]      = (byte)((byte)Math.Sqrt((Math.Pow(pixels1[i], 2) + Math.Pow(pixels2[i], 2))) % byte.MaxValue);
            pixels1[i + 1] =  (byte)((byte)Math.Sqrt((Math.Pow(pixels1[i + 1], 2) + Math.Pow(pixels2[i + 1], 2))) % byte.MaxValue);
            pixels1[i + 2] =  (byte)((byte)Math.Sqrt((Math.Pow(pixels1[i + 2], 2) + Math.Pow(pixels2[i + 2], 2))) % byte.MaxValue);
        }

        WriteableBitmap bmp = new WriteableBitmap((int)decoder1.OrientedPixelWidth, (int)decoder1.OrientedPixelHeight);

        using (Stream stream = bmp.PixelBuffer.AsStream())
        {
            await stream.WriteAsync(pixels1, 0, pixels1.Length);
        }

   } 
4

1 に答える 1

4

IBuffer.AsStream()拡張メソッドです。使用する場合は、定義されている名前空間を含める必要があります。

using System.Runtime.InteropServices.WindowsRuntime;

更新: 以下のコメントで述べているように、書き込み可能なビットマップについてはあまり行っていません。ただし、コードは透明度の値を設定していません。これは、少なくとも問題の一部である可能性があります。

for (int i = 0; i < pixels1.Length; i += 4){
    pixels1[i]      = (byte)((byte)Math.Sqrt((Math.Pow(pixels1[i], 2) + Math.Pow(pixels2[i], 2))) % byte.MaxValue);
    pixels1[i + 1] =  (byte)((byte)Math.Sqrt((Math.Pow(pixels1[i + 1], 2) + Math.Pow(pixels2[i + 1], 2))) % byte.MaxValue);
    pixels1[i + 2] =  (byte)((byte)Math.Sqrt((Math.Pow(pixels1[i + 2], 2) + Math.Pow(pixels2[i + 2], 2))) % byte.MaxValue);
}

次のようにする必要があります。

for (int i = 0; i < pixels1.Length; i += 4){
    pixels1[i]      = (byte)((byte)Math.Sqrt((Math.Pow(pixels1[i], 2) + Math.Pow(pixels2[i], 2))) % byte.MaxValue);
    pixels1[i + 1] =  (byte)((byte)Math.Sqrt((Math.Pow(pixels1[i + 1], 2) + Math.Pow(pixels2[i + 1], 2))) % byte.MaxValue);
    pixels1[i + 2] =  (byte)((byte)Math.Sqrt((Math.Pow(pixels1[i + 2], 2) + Math.Pow(pixels2[i + 2], 2))) % byte.MaxValue);
    pixels1[i + 3] = 255; // or some combination of the source data. 0 == completely transparent.
}
于 2013-02-15T04:25:24.700 に答える