How to display 3 single channel array in wpf?

Tamil Prakash S 1 Reputation point
2020-06-12T10:31:41.967+00:00

I have 3 IntPtr Pointers of Red, Green, and Blue channels. I need to display these pointers as an RGB image. I know the width and height of the image. If I convert it as a single pointer it takes processing cost.

Here is my Conversion Code,

public static void UpdateImage(WriteableBitmap wbitmap, IntPtr red, IntPtr green, IntPtr blue, int totalSize, int width, int height)
{        
    unsafe
    {
        byte* redByt = (byte*)red;
        byte* blueByt = (byte*)blue;
        byte* greenByt = (byte*)green;
        byte* buffer = (byte*)wbitmap.BackBuffer;

        for (int i = 0; i < totalSize; i+=3)
        {
            buffer[i ] = redByt[i];
            buffer[i + 1] = blueByt[i];
            buffer[i+ 2] = greenByt[i];
        }
        wbitmap.Lock();
        wbitmap.AddDirtyRect(new System.Windows.Int32Rect(0, 0, width, height));
        wbitmap.Unlock();
    }
}

I need to display these 3 single channeled pointers to UI without above conversion, Is there any way?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,667 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2020-06-14T15:41:43.49+00:00

    Not exactly sure what you are asking. There is a thing called an IValueConverter you can use to Modify the image before you display it.

    https://www.wpftutorial.net/ValueConverters.html

    https://learn.microsoft.com/en-us/dotnet/api/system.windows.data.ivalueconverter?view=netcore-3.1

    0 comments No comments