Terrence
Terrence

Reputation: 341

Taking a Picture, and saving it to Disk in a Windows 8 Metro-style App

I am ABLE to take a picture, but I am having trouble saving it to one of the KnownFolders. Yes, I have declared the Picture Library Access Capability in Package.appxmanifest.

var ui = new CameraCaptureUI();

ui.PhotoSettings.CroppedAspectRatio = new Size(4, 3);
StorageFile file = await ui.CaptureFileAsync(CameraCaptureUIMode.Photo);

if (file != null)
{
    var stream = await file.OpenAsync(FileAccessMode.Read);
    var bitmap = new BitmapImage();
    bitmap.SetSource(stream);
    Photo.Source = bitmap;
    StorageFolder storageFolder = KnownFolders.PicturesLibrary;
    var result = await file.CopyAsync(storageFolder, "tps.jpg");
}

The code stops on the last line. What am I doing wrong?

Upvotes: 0

Views: 815

Answers (1)

shenhengbin
shenhengbin

Reputation: 4294

I think you also need declare the file types!

  • In the Declarations tab, choose File Type Associations from Available Declarations and click Add.
  • Under Properties, set the Name property to image.
  • In the Supported File Types box, add .jpg as a supported file type by entering .jpg in the FileType field.

Upvotes: 1

Related Questions