Search code examples
c#windows-phone-8bitmapnokia-imaging-sdklumia-imaging-sdk

How to access pixels behind IImageProvider (Nokia Imaging SDK on WP8)


I have an image source behind IImageProvider interface, and I'm trying to access its pixels.

There is a method inside IImageProvider: imageProvider.GetBitmapAsync(bitmapToFill)

  • I can't get WriteableBitmap because I'm running on a non UI thread. I can't instantiate one empty WriteableBitmap to write to which is unfortunate because I can access pixels from it..
  • I can fill a Bitmap object with the data, but there is no way to access its pixels on Windows Phone (it is missing system.drawing...)

How can I access individual pixels of the source behind IImageProvider?


Solution

  • Have you tried this?

    var bitmap = await imageSource.GetBitmapAsync(null, OutputOption.PreserveAspectRatio);
    var pixels = bitmap.Buffers[0];
    for (uint i = 0; i < pixels.Buffer.Length; i++)
        {
            var val = pixels.Buffer.GetByte(i);
        }
    
    • i = R ... [0]
    • i+1 = G ... [1]
    • i+2 = B ... [2]
    • i+3 = A ... [3]

    and so on

    imageSource is your IImageProvider, I tested it with BufferImageSource.