This project is read-only.

How to use this library efficiently and correctly

Dec 31, 2012 at 5:44 PM



When I added the  WriteableBitmapExtensions.Convolute on an 480x800 image, the UI seems a little slower to response. So I use a BackgroundWork to do the post processing. However, I got System.UnauthorizedAccessException when do this:

WriteableBitmap wb = new WriteableBitmap((BitmapImage)e.Argument);
What is a correct way to pass bitmap to BackgroundWorker? Here is the code:

    private void LoadImage(object sender, DoWorkEventArgs e)
        WriteableBitmap wb = new WriteableBitmap((BitmapImage)e.Argument);
        wb.Resize(AppWidth, AppHeight, WriteableBitmapExtensions.Interpolation.Bilinear);
        var wb2 = WriteableBitmapExtensions.Convolute(wb, WriteableBitmapExtensions.KernelGaussianBlur3x3);            
        e.Result = wb2;

    private void LoadImageCompleted(object sender, RunWorkerCompletedEventArgs e)
        AlbumBackground.ImageSource = (WriteableBitmap)e.Result;
I also tried to move the creation of WriteableBitmap to the UI thread and pass WriteableBitmap to Worker thread. It has InvalidOperation exception. I read a post saying that the BitmapImage has 2 buffers and it is not meant to be altered by different thread. How to workaround this? Or if I have done blurring image incorrectly?

Jan 20, 2013 at 3:37 PM

Use the Async Methods available for creating a WriteableBitmap. If the methods are not Async, you can dispatch them to the UI thread asynchronously to have them load later.

Jan 23, 2013 at 8:09 AM

The new WriteableBitmap ctor call needs to happen on the UI thread. If you want to use it in a background thread create the bitmap before and use the code of the Convolute method in your own implementation.