Comments: ** Comment from web user: teichgraf **
We added DrawPolygonEvenOdd which supports that.
We added DrawPolygonEvenOdd which supports that.
Just fixed this in chageset 113259 by using CohenSutherlandLineClip for DrawLineAa and DrawLine
Thanks for raising this. This was just fixed in the latest source code and will be part of the next release. If you need it now, just get latest source code and rebuild the lib locally or take the #if WPF part of the FromStream method into your code.
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! WriteableBitmap currPicture = new WriteableBitmap((BitmapSource)(new __BitmapImage(new Uri(allPictures[i]))));__
Sometimes it might have been loaded but that's good luck.var wbs = new List<WriteableBitmap>();
foreach(var fileName in Directory.GetFiles(selectFolder(), filePrefix + "*.png", SearchOption.AllDirectories))
{
using(var stream = File.OpenRead(fileName))
{
var wb = BitmapContext.New(1, 1).FromStream(stream);
wbs.Add(wb);
}
}
Parallel.For(0, wbs.Count, i =>
{
var currPicture = wbs[i];
SumPictures(currPicture);
if (i == 0)
...
public static WriteableBitmap MyFromStream(WriteableBitmap bmp, Stream stream)
{
var bmpi = new BitmapImage();
bmpi.BeginInit();
bmpi.StreamSource = stream;
bmpi.EndInit();
bmp = new WriteableBitmap(bmpi);
return bmp;
}
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);
wbs.Add(wb);
}
}
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];
SumPictures(currPicture);
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?I assume you were using it on WPF?
Keep in mind that the WB uses pre-multiplied so the RGB components are already multiplied with their alpha values on most platforms, so performing sr * sa actually means (sr*sa) * sa. I added an additional check for the WPF build if the source.Format is pRGBA. This should work for all cases now. Please get latest source code from the repository and try it.
Thanks for raising this issue.
Hello,
thank you for explanation.
I have used version from official downloads, with some fixes and extension. When upgrading to latest source code version, it works perfectly.
Only when upgrading, FillRectangle function draws rectangles one pixel smaller than previous rectangle... I fixed it in my calling code.
Jan
Sorry for typing error is mean:
FillRectangle function draws rectangles one pixel smaller than previous __version__