public static BitmapSource CreateNew(int newWidth, int newHeight) { var img = new Image(); if (img.CreateNew(newWidth, newHeight)) { return(new BitmapSource(img)); } throw new ApplicationException("Failed to create image: " + img.ErrorMsg[img.LastErrorCode]); }