Ive been trying to follow this suggestion but havent been able to so far. How should I change it to make this work?
The crazy thing here is that this work for a larger image (full hd) but not for a 512x424 image.
This is the code im using:
The crazy thing here is that this work for a larger image (full hd) but not for a 512x424 image.
This is the code im using:
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. The console output prints the PixelWidth and PixelHeight correctly
Console.WriteLine("Col: " + col + " row: " + row + " currPicture.PixelWidth: " + currPicture.PixelWidth + " currPicture.PixelHeight: " + currPicture.PixelHeight);
_sumedAllImages[col][row].R += currPixel.R;
_sumedAllImages[col][row].G += currPixel.G;
_sumedAllImages[col][row].B += currPixel.B;
_sumedAllImages[col][row].A += currPixel.A;
}
}
}
private void LoadAndAverageImages(string filePrefix)
{
string[] allPictures = Directory.GetFiles(selectFolder(), filePrefix + "*.png", SearchOption.AllDirectories);
//for (int i = 0; i < allPictures.Length; i++)
Parallel.For(0, allPictures.Length, i =>
{
_filenameList.Add(allPictures[i]);
WriteableBitmap currPicture = new WriteableBitmap((BitmapSource)(new BitmapImage(new Uri(allPictures[i]))));
SumPictures(currPicture);
if (i == 0)
_samplePicture = currPicture;
Console.WriteLine("currPicture: " + i);
});
for (int col = 0; col < _samplePicture.PixelWidth; col++)
{
for (int row = 0; row < height; row++)
{
Color currPixelSum = new Color();
currPixelSum.R = (byte)_sumedAllImages[col][row].R;
currPixelSum.G = (byte)_sumedAllImages[col][row].G;
currPixelSum.B = (byte)_sumedAllImages[col][row].B;
currPixelSum.A = (byte)_sumedAllImages[col][row].A;
_samplePicture.SetPixel(col, row, currPixelSum);
}
}
Console.WriteLine("Loaded " + allPictures.Length + " pictures!");
}
Thank you!