I have an application c# wpf and I use Image Bitmap.
I have a Byte [] who contains value (0 or 255) used to draw an image in gray scale.
Example :
int heigth = 5;
int width = 5;
Byte[] image = new Byte[]
{ 255, 0, 255, 0, 255,
0, 255, 255, 255, 0,
255, 255, 0, 255, 250,
0, 255, 255, 255, 0,
255, 0, 255, 0, 255};
Corresponds to the image
To display this image in my application I did that :
XAML :
<Border Style="{StaticResource BorderStyle}">
<Image Source="{Binding BlockPicture, Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" />
</Border>
C# :
private BitmapSource _blockPicture;
public BitmapSource BlockPicture
{
get
{
return _blockPicture;
}
private set
{
_blockPicture = value;
OnPropertyChanged("BlockPicture");
}
}
private BitmapSource LoadImage(int w, int h, byte[] matrix)
{
if (matrix == null || matrix.Length == 0)
return null;
var format = PixelFormats.Gray8;
var stride = (w * format.BitsPerPixel + 7) / 8;
return BitmapSource.Create(w, h, 96, 96, format, null, matrix, stride);
}
BlockPicture = LoadImage(width, heigth , image);
It's work fine but when the image is displayed, it's very ugly and diffuse.
What can I do to have a nice picture clean and sharp ?

