The idea is to process a loaded image. I first wanted to process it that way, that there is a white/black line going through the image. Actual the problem is, that a new Thread (for Thread.Sleep) freezes the whole UI, while processing. And when I try a Dispatcher, the image doesn't update.
So I got a ProcessingClass:
public WriteableBitmap GetProcessedPicture(int i)
{
WriteableBitmap wb = image.image;
Process(ref wb, i);
return wb;
}
private void Process(ref WriteableBitmap wb, int j)
{
int stride = wb.PixelWidth * (wb.Format.BitsPerPixel + 7) / 8;
byte[] data = new byte[stride * wb.PixelHeight];
for (int i = 0; i < data.Length; i++) data[i] = 255;
//just to see some changes
wb.WritePixels(new Int32Rect(j, 0, 100, 100), data, stride, 0);
}
And the MainViewModel class (I'm using MVVM light) with:
public void Start_Click()
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
for (int i = 0; i < 100; i++)
{
ImageSource = processingClass.GetProcessedPicture(i);
Thread.Sleep(100);
}
}));
};
Thanks for the help.