Quantcast
Channel: WriteableBitmapEx
Viewing all articles
Browse latest Browse all 360

New Post: AccessViolationException when accessing pixel color (GetPixel())

$
0
0
Same issues. You want to access the pixels but the loading is asynchronously, so the pixel data was not loaded.
            WriteableBitmap currPicture = new WriteableBitmap((BitmapSource)(new __BitmapImage(new Uri(allPictures[i]))));__
Sometimes it might have been loaded but that's good luck.

You should rather use the WBX method FromStream(stream)
Also, you can't create a WB on a background thread so running the creation of WBs needs to happen before your Parallel loop on the UI thread.

Something like this (not tested nor compiled);
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)
...

Viewing all articles
Browse latest Browse all 360

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>