Mar 21, 2015 at 5:04 AM
Edited Mar 21, 2015 at 5:09 AM
So the error I had when opening a new Image is now gone, but Im still seeing the same error when getting a single pixel from the loaded image.
The code is basicly the same you posted, but I had to make my own FromStream method, which goes as follows:
public static WriteableBitmap MyFromStream(WriteableBitmap bmp, Stream stream)
var bmpi = new BitmapImage();
bmpi.StreamSource = stream;
bmp = new WriteableBitmap(bmpi);
And its accessed like this:
var wbs = new List<WriteableBitmap>();
for ( int i = 0; i < allPictures.Length; i++ )
using( var stream = File.OpenRead( allPictures[i]) )
//var wb = BitmapFactory.New(1, 1).FromStream(stream);
var wb = MyFromStream(BitmapFactory.New(1, 1), stream);
So the error is happening here now. What is the right way of accessing a single pixel? Just to make it crystal clear, I need to access the whole image, pixel by pixel.
//for (int i = 0; i < allPictures.Length; i++)
Parallel.For(0, wbs.Count, i =>
var currPicture = wbs[i];
if (i == 0)
_samplePicture = currPicture;
Console.WriteLine("currPicture: " + i);
private void SumPictures( WriteableBitmap currPicture )
for (int col = 0; col < currPicture.PixelWidth; col++)
for (int row = 0; row < currPicture.PixelHeight; row++)
Color currPixel = currPicture.GetPixel(col, row); //<-- Error happens here.
_sumedAllImages[col][row].R += currPixel.R;
_sumedAllImages[col][row].G += currPixel.G;
_sumedAllImages[col][row].B += currPixel.B;
_sumedAllImages[col][row].A += currPixel.A;
And for last, but not least, when calling BitmapFactory.New(1,1), the description says that New receives the Width and Height of the newly created WriteableBitmap, so how come Im passing it as 1?
Thanks for the support!