2013-02-14 2 views
1

나는 두 개의 이미지를 WriteableBitmaps로 병합하려고합니다. 각 픽셀 값을 정사각형으로 만들고 다른 이미지에 추가 한 다음 두 번째 루트 (값이 255 이상인 경우 + 확인)를 가져오고 싶습니다. WriteableBitmapEx 및 ForEach() (Sobel operator & Convolution with WriteableBitmapEx) (꽤 느린 것 같습니다)를 사용하여 행운을 얻지 못했기 때문에 BitmapDecoder를 사용하여 직접 픽셀을 조작 해 보았습니다.WriteableBitmap 픽셀 조작

'Windows.Storage.Streams.IBuffer가'AsStream '최고의 확장 방법에 대한 정의가 포함되어 있지 않습니다 불행히도 나는이 오류를 얻을 수로, 다시 WriteableBitmap에 Pixelstream을 쓸 수없는 것 과부하 'System.IO.WindowsRuntimeStreamExtensions.AsStream (Windows.Storage.Streams.IRandomAccessStream)' 는 일부 잘못된 인수를

인스턴스 인수를 가지고 :로 변환 할 수 없습니다 에 17,451,515,'Windows.Storage.Streams.IBuffer'는 WriteableBitmapEx 라이브러리가 생겼습니다

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

이 뭔가 될 수있는 이러한 라인 'Windows.Storage.Streams.IRandomAccessStream'

?

또한 내 WriteableBitmaps를 BitmapDecoders에 가져 오는 방법에 대해 궁금합니다. 이 코드는 Win8 Coding 책에서 가져 왔습니다.

여기에 지금까지 내 전체 코드입니다 :

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); 
     } 

    } 
+0

내가 아는 한 BitmapDecoder에 직접 픽셀을 작성하는 단지 불가능이 적어도 문제의 일부가 될 수 있습니다. 그런데 왜 그걸하고 싶니? 어딘가에 표시 할 WriteableBitmap이 있습니다. BitmapEncoder에 픽셀을 써서 비트 맵을 저장할 수 있습니다. 그 밖의 무엇을하고 싶습니까? –

답변

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. 
} 
+0

고마워요, 그게 전부입니다. WriteableBitmap을 BitmapDecoder로 가져 오는 방법을 알려주시겠습니까? – Thomas

+0

죄송합니다.'WriteableBitmap'을 많이 사용하지 않았습니다. 내가 본 모든 것은'BitmapDecoder'에서'WriteableBitmap'으로, ** WriteableBitmap에서'BitmapDecoder'로 ** 이동하지 않습니다. 예를 들어 http://stackoverflow.com/questions/14718855/how-to-create-writeablebitmap-from-bitmapimage –

+0

여기에 같은 질문이 있습니다. – Thomas