简体   繁体   English

如何使用 xamarin 将照片保存在 android 的图库文件夹中

[英]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.

相关问题 如何使用 Xamarin 在 Android 上的图库中请求保存图像的授权? - How to ask authorization for save image in Gallery on Android using Xamarin? 在Xamarin Android上拍照后如何将照片发送到drawable文件夹? - How to send a photo to the drawable folder after take the photo on Xamarin Android? 如何将照片从画廊保存到Xamarin中Windows服务器上的共享文件夹 - How to save photos from gallery to shared folder on a windows server in xamarin 如何在 Android Image Gallery 中从 unity 中保存拍摄的照片? - How to save a captured photo from unity in Android Image Gallery? 如何将我的照片从 tmp 目录文件夹保存到 xamarin iOS 中的库/文档文件夹 - How Do I Save my photo from tmp directory folder to library/ document folder in xamarin iOS 如何从 url 下载照片并保存在 Xamarin - How to download a photo from url and save in Xamarin 如何以 xamarin 形式将视频保存到图库 - how to save videos to the gallery in xamarin forms 如何在 C# xamarin forms android 中保存具有特定名称的照片? - how can I save a photo with an specific name in C# xamarin forms android? 将位图保存到Pictures文件夹(Xamarin Android) - Save bitmap to Pictures folder (Xamarin Android) 能够拍摄或 Select 照片来自 Xamarin 中的图库 - Ability to Take or Select Photo from Gallery in Xamarin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM