Reputation: 137
I have to write functions which is setting pixel in WPF. I need to draw some pictures. Using attached code I have some blurry effect (like on screen).
Can you tell me what is wrong, or which methods I should use ?
namespace DisplayAppCS {
public partial class MainWindow : Window
{
WriteableBitmap _bitmap = new WriteableBitmap(100, 200, 1, 1, PixelFormats.Bgr32, null);
public MainWindow()
{
InitializeComponent();
image1.SnapsToDevicePixels = true;
image1.Source = _bitmap;
int[] ColorData = { 0xFFFFFF }; // B G R
Int32Rect rect = new Int32Rect(
1,
60,
1,
1);
_bitmap.WritePixels(rect, ColorData, 4, 0);
}
}}
Upvotes: 0
Views: 631
Reputation: 178660
Your bitmap is 100x200 but your window is much larger. Your image is being stretched to the size of the window, thus creating the "blurring" effect. You need to either change the size of the window or tell the image not to stretch:
<Image Stretch="None"/>
That said, you could be going down completely the wrong path using a writeable bitmap. It really depends on your requirements. Could you get away with just using built-in WPF shapes, for example?
Upvotes: 4