image_gallery_saver_plus_ohos:基于 Flutter 的媒体保存插件项目

用户可直接下载并保存图片和视频到相册,该项目作为更新后的插件,具备增强性能、改进的媒体组织功能及跨设备更好的兼容性。【此简介由AI生成】

Branch1Tags0
FilesLast commitLast update
1 year ago
1 year ago
2 years ago
8 months ago
8 months ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
9 months ago

image_gallery_saver_plus

pub package license

这是一款更新后的插件,能让用户直接将图片和视频下载并保存到相册,它具备更出色的性能、更完善的媒体整理功能,以及在各类设备上更好的兼容性。

使用方法

要使用此插件,请在您的 pubspec.yaml 文件中添加 image_gallery_saver_plus 作为依赖项。例如:

dependencies:
  image_gallery_saver_plus: ^4.0.1

iOS

您的项目需要使用 Swift 创建。 将以下键添加到 Info.plist 文件中,该文件位于 /ios/Runner/Info.plist:

<key>NSPhotoLibraryAddUsageDescription</key>
<string>We need permission to save photos and videos to your library for your convenience.</string>

<key>NSPhotoLibraryUsageDescription</key>
<string>We need permission to access your photo library to view and select your photos and videos.</string>

Android

要将图片保存到图库,您需要申请存储权限。您可以使用 flutter_permission_handler 来处理存储权限。 在 Android 10 版本中,请打开清单文件,并在您的应用程序标签中添加以下行

 <application android:requestLegacyExternalStorage="true" .....>

示例

从互联网保存图片,质量和名称为可选参数

  _saveLocalImage() async {
    RenderRepaintBoundary boundary =
        _globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
    ui.Image image = await boundary.toImage();
    ByteData? byteData =
        await (image.toByteData(format: ui.ImageByteFormat.png));
    if (byteData != null) {
      final result =
          await ImageGallerySaverPlus.saveImage(byteData.buffer.asUint8List());
      print(result);
    }
  }
  
  _saveNetworkImage() async {
    var response = await Dio().get(
        "https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=a62e824376d98d1069d40a31113eb807/838ba61ea8d3fd1fc9c7b6853a4e251f94ca5f46.jpg",
        options: Options(responseType: ResponseType.bytes));
    final result = await ImageGallerySaverPlus.saveImage(
        Uint8List.fromList(response.data),
        quality: 60,
        name: "hello");
    print(result);
  }

从互联网保存文件(如:视频/ gif /其他)

  _saveNetworkGifFile() async {
    var appDocDir = await getTemporaryDirectory();
    String savePath = appDocDir.path + "/temp.gif";
    String fileUrl =
        "https://hyjdoc.oss-cn-beijing.aliyuncs.com/hyj-doc-flutter-demo-run.gif";
    await Dio().download(fileUrl, savePath);
    final result =
        await ImageGallerySaverPlus.saveFile(savePath, isReturnPathOfIOS: true);
    print(result);
  }

  _saveNetworkVideoFile() async {
    var appDocDir = await getTemporaryDirectory();
    String savePath = appDocDir.path + "/temp.mp4";
    String fileUrl =
        "https://s3.cn-north-1.amazonaws.com.cn/mtab.kezaihui.com/video/ForBiggerBlazes.mp4";
    await Dio().download(fileUrl, savePath, onReceiveProgress: (count, total) {
      print((count / total * 100).toStringAsFixed(0) + "%");
    });
    final result = await ImageGallerySaverPlus.saveFile(savePath);
    print(result);
  }

Introduction

用户可直接下载并保存图片和视频到相册,该项目作为更新后的插件,具备增强性能、改进的媒体组织功能及跨设备更好的兼容性。【此简介由AI生成】

Customize your domain