Can you move this code into createThumbnailFromSource() since you already have a canvas with the pixels in it there?  I think that would be the better way to handle it.