1

I'm attempting to develop a camera app for Windows 8 using C#.

My code:

public string newFilename { get; set; }
private StorageFile photo;
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
    t1.Text = System.DateTime.Now.Date.ToString();
    CameraCaptureUI cam = new CameraCaptureUI();
    cam.PhotoSettings.CroppedAspectRatio = new Size(6, 4);
    var photo = await cam.CaptureFileAsync(CameraCaptureUIMode.Photo);

    //StorageFile photo = await cam.CaptureFileAsync(CameraCaptureUIMode.Photo);
    //if (photo != null)
    //{
    //    var targetFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("IMAGE11.jpg");
    //    if (targetFile != null)
    //    {
    //        await photo.MoveAndReplaceAsync(targetFile);
    //    }
    //}

    if (photo != null)
    {
        IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read);
        var bitmap = new BitmapImage();
        bitmap.SetSource(await photo.OpenAsync(FileAccessMode.ReadWrite));
        BitmapImage img = new BitmapImage();
        im1.Source = bitmap;
        //StorageFile sample = await localfolder.CreateFileAsync("img.png", CreationCollisionOption.GenerateUniqueName);
    }
}

private async void Button_Click_1(object sender, RoutedEventArgs e)
{
    if (photo != null)
    {
        await photo.MoveAsync(ApplicationData.Current.LocalFolder,newFilename);
    }
}

My app shows the captured camera image.

My question is: How can I store the captured camera images in a local folder?

Luke Willis
  • 8,429
  • 4
  • 46
  • 79
suresh
  • 113
  • 11
  • 1
    Well, what's the problem with the commented out lines you've tried? – millimoose Aug 23 '13 at 19:40
  • 1
    So, you want to save a BitmapImage to a file. http://stackoverflow.com/questions/4161359/save-bitmapimage-to-file – Bob2Chiv Aug 23 '13 at 19:48
  • [This](http://social.msdn.microsoft.com/Forums/windowsapps/en-US/40b76a69-4f94-4622-b928-5f31c7cfb98b/saving-bitmapimage-to-file) may be of use to you. Also [this](http://stackoverflow.com/questions/9423565/how-do-i-take-a-bitmap-image-and-save-as-a-jpeg-image-file-on-a-windows-phone-7) – Bob2Chiv Aug 23 '13 at 20:02

0 Answers0