GetPixel throws an AccessViolationException

Apr 11, 2013 at 11:20 PM
Hi, I am quite new to WriteableBitmapEx. I tried to load a png file in a WinRT Project by using a WriteableBitmap object and WriteableBitmapEx included via nuget.
The Image is

My code is
        async void MainPage_Loaded(object sender, RoutedEventArgs e)
            WriteableBitmap image = new WriteableBitmap(100, 100);

            StorageFile file = await Package.Current.InstalledLocation.GetFileAsync("Assets\\Plan_cathedrale_Amiens.png");

            IRandomAccessStreamWithContentType randomAccessStream = await file.OpenReadAsync();
        private void Transform(WriteableBitmap source)
            Color bottomleft = source.GetPixel(5, 5);
The line Color bottomleft = source.GetPixel(5, 5); is the one goind bad and throwing an AccessViolationException.

I would very much appreciate any help.

Best Regards,
Apr 12, 2013 at 7:47 AM
It's simply not loaded at the time you want to access the pixels. Just check the PixelWidth and Height properties.
You should use the WBX methods to load your stuff:
Uri imageUri = new Uri(BaseUri, "///Assets/Plan_cathedrale_Amiens.png");
image = await BitmapFactory.New(1, 1).FromContent(imageUri);
  • Rene