【问题标题】:C# Saving Jpeg to specific path localC# 将 Jpeg 保存到本地的特定路径
【发布时间】:2014-01-16 10:42:49
【问题描述】:

我正在构建一个需要使用网络摄像头拍照并将其保存到本地磁盘的应用程序,到目前为止我有这个:

async private void CapturePhoto_Click(object sender, RoutedEventArgs e)
    {
        Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
        ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();


        // create storage file in local app storage
        StorageFile file = await localFolder.CreateFileAsync("TestPhoto.jpg", CreationCollisionOption.GenerateUniqueName);

        StorageFile localFile = await localFolder.CreateFileAsync("webcamPhotoTest.jpg", CreationCollisionOption.ReplaceExisting);

        // take photo 
        // save to app storage
        await captureManager.CapturePhotoToStorageFileAsync(imgFormat, file);

        // save to local storage
        await captureManager.CapturePhotoToStorageFileAsync(imgFormat, localFile);

        // Get photo as a BitmapImage
        BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));

        // imagePreview is a <Image> object defined in XAML
        imagePreview.Source = bmpImage;

    }

我可以将 jpg 图像同时保存到应用存储和本地存储,但我需要能够 a) 指定保存路径 b) 这样做不需要用户交互(例如 windows 保存文件提示)

Windows 8 应用程序不支持 System.Drawing,这使事情变得复杂。我发现的大多数答案要么是使用 System.Drawing 功能,要么是 Windows 的保存文件提示。

【问题讨论】:

  • 您知道要保存在哪里吗?也许看这里:stackoverflow.com/questions/4161359/save-bitmapimage-to-file
  • 是的,但现在任何地方都可以。以后可以随时更改路径。要点是能够指定它。您提供的链接似乎是关于下载和保存,而不是从应用程序中保存。

标签: c# windows-store-apps


【解决方案1】:

你不能真正使用你想要的任何位置。您可以从应用程序访问的位置列表:File access and permissions in Windows Store apps。某些位置需要在项目的清单文件中进行额外声明。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-15
    • 2014-03-14
    相关资源
    最近更新 更多