如何获取智能手机内存和DCIM文件夹的路径? [英] How to get the path to the internal memory of the smartphone and the DCIM folder?

查看:44
本文介绍了如何获取智能手机内存和DCIM文件夹的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取智能手机内存的路径和DCIM文件夹,然后将照片保存在那里?

How to get the path to the internal memory of the smartphone and the DCIM folder, then to save the photo there?

string directory = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads);
FileStream file = new FileStream(System.IO.Path.Combine(directory, "newProdict_" + product.Width + "x" + product.Height + ".png"), FileMode.OpenOrCreate);

推荐答案

您可以像这样获取 DCIM 文件夹:

You can get the DCIM folder like that:

var dcimFolder = Android.OS.Environment.GetExternalStoragePublicDirectory(System.Environment.DirectoryDcim).Path;

对于写入文件,您可以使用 nuget 包 PCLStorage,因此您已经拥有跨平台的所有内容方式:

For writing files you can use the nuget package PCLStorage so you already have everything in a cross platform manner:

var folder = await FileSystem.Current.GetFolderFromPathAsync(dcimFolder);
var file = await folder.CreateFileAsync("image.jpg", CreationCollisionOption.ReplaceExisting);
byte[] buffer = new byte[100];
using (System.IO.Stream stream = await file.OpenAsync(FileAccess.ReadAndWrite))
{
    stream.Write(buffer, 0, 100);
}

这篇关于如何获取智能手机内存和DCIM文件夹的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆