Saving a BitmapImage object as a file in local sto

2019-07-21 07:23发布

问题:

I have a BitmapImage object, which already has its source etc set. I simply want to save it to my apps local storage folder, so that I can reference it at other points in the program. I just cannot figure out how to get it from object to file though! I've found solutions to similar problems for WP7, but its just not the same.

Ive got as far as creating my image from a Base64 string (which works as I can load the image into a UI image viewer and see it) and have called it img, and I know I need to get it to ApplicationData.Current.LocalFolder, but I have no idea how to convert it. Does anyone know?

回答1:

Is it from the camera UI?

var _Photo = await new CameraCaptureUI()
    .CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);
await _Photo.MoveAsync(ApplicationData.Current.LocalFolder);

Is it from opening the file? Then you just need:

await _Photo.MoveAsync(ApplicationData.Current.LocalFolder);

However, if you simply have a BitmapImage, you cannot get the image out of it. Instead you need to go back to the original source or file. That's the only way. Reference