How To Display 8-bit Grayscale BitmapImage

Environment

Product Version 2019.3.917
Product RadImageEditor for WPF

Solution

To show a grayscale image, you can use the FormatConvertedBitmap class as shown in the following article. The following code snippet demonstrate this approach:

private void CreateGrayScaleImage() 
{ 
    var bmpImage = new BitmapImage(); 
    bmpImage.BeginInit(); 
    bmpImage.UriSource = new Uri(@"C:\images\myImage.png", UriKind.RelativeOrAbsolute); 
    bmpImage.EndInit(); 
 
    var grayBitmap = new FormatConvertedBitmap(); 
    grayBitmap.BeginInit(); 
    grayBitmap.Source = bmpImage; 
    grayBitmap.DestinationFormat = PixelFormats.Gray8; 
    grayBitmap.EndInit(); 
 
    this.radImageEditor.Image = new RadBitmap(grayBitmap); 
} 
In this article
Not finding the help you need? Improve this article