[英]how to save photo in gallery folder in android using xamarin
How to save photo in gallery folder?如何将照片保存在图库文件夹中? I am using ImageCropper.Forms.Fix.v2 and Xam.Media.Plugin
我正在使用 ImageCropper.Forms.Fix.v2 和 Xam.Media.Plugin
code is working fine, but it saving in location: /data/user/0/com.companyname.projectname/cache/cropped3243.png代码工作正常,但它保存在位置:/data/user/0/com.companyname.projectname/cache/cropped3243.png
i want to save it in gallery folder.我想将它保存在画廊文件夹中。 how can i do this?
我怎样才能做到这一点?
protected async void TapGestureRecognizerCommand(object sender, EventArgs e)
{
await CrossMedia.Current.Initialize();
ImageSource TempimageFile = null;
new ImageCropper()
{
PageTitle = "Crop Photo",
AspectRatioX = 3, //
CropShape = ImageCropper.CropShapeType.Rectangle, //Cropt shape
SelectSourceTitle = "Select source", // Pop up Title
TakePhotoTitle = "Take Photo", // Popup - 1st option
PhotoLibraryTitle = "Photo Library", //Popup - 2nd option
Success = (imageFile) =>
{
Device.BeginInvokeOnMainThread(() =>
{
TempimageFile = ImageSource.FromFile(imageFile);
DisplayAlert("test", "te: " + TempimageFile, "OK");
ImageURL.Source = TempimageFile;
});
}
}.Show(this);
}
For example,you could use DependencyService to call the natvie method to save it to the system photo album.例如,您可以使用DependencyService调用 natvie 方法将其保存到系统相册中。
create a interface in your forms project:在 forms 项目中创建一个接口:
public interface ISaveToGallery
{
void Save(string filePath,string fileName);
}
then in you Android project:然后在你的 Android 项目中:
class SaveToGallery: ISaveToGallery
{
public void Save(string filePath, string fileName)
{
MediaStore.Images.Media.InsertImage(Android.App.Application.Context.ContentResolver,
filePath, fileName, null);
}
}
the call it like:像这样称呼它:
protected async void TapGestureRecognizerCommand(object sender, EventArgs e)
{
await CrossMedia.Current.Initialize();
ImageSource TempimageFile = null;
new ImageCropper()
{
PageTitle = "Crop Photo",
AspectRatioX = 3, //
CropShape = ImageCropper.CropShapeType.Rectangle, //Cropt shape
SelectSourceTitle = "Select source", // Pop up Title
TakePhotoTitle = "Take Photo", // Popup - 1st option
PhotoLibraryTitle = "Photo Library", //Popup - 2nd option
Success = (imageFile) =>
{
Device.BeginInvokeOnMainThread(() =>
{
TempimageFile = ImageSource.FromFile(imageFile);
DisplayAlert("test", "te: " + TempimageFile, "OK");
ImageURL.Source = TempimageFile;
DependencyService.Get<ISaveToGallery>().Save(imageFile,"your file name");
});
}
}.Show(this);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.