2016-07-21 8 views
0

Ich habe eine Anwendung C# wpf und ich verwende Bild Bitmap.Make Bitmap Bild scharf

Ich habe eine Byte [] Wer enthält Wert (0 oder 255) verwendet, um ein Bild in Graustufen zu zeichnen.

Beispiel:

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

Entspricht das Bild

Image pattern

in meiner Anwendung dieses Bild anzuzeigen, habe ich das:

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

Es ist Arbeit gut, aber wenn das Bild angezeigt wird, ist es sehr hässlich und diffus.

Displayed image

Was kann ich ein schönes Bild sauber und scharf haben?

Antwort

3

können Sie geben die BitmapScalingMode:

<Image RenderOptions.BitmapScalingMode="NearestNeighbor" /> 
+0

, dass genau das, was ich will. Vielen Dank ! –