搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.3

image_gallery_saver

一個用於將影像儲存至相簿的 Flutter 插件,iOS 需要將下列鍵新增至您的 Info.plist 檔案中。

AndroidiOS
近 30 天下載
1.9萬
喜歡數
885
Pub 分數
150

安裝套件

flutter pub add image_gallery_saver

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

image_gallery_saver 套件是一個 Flutter 插件,可在 Android 與 iOS 上將影像儲存至裝置相簿。它提供簡單的 API,可將位元資料或檔案路徑作為影像儲存至系統相片圖庫中。在 iOS 上,使用者必須於 Info.plist 檔案中加入特定金鑰以取得存取權限。此套件非常適合需要提供「儲存至相簿」功能之產生或下載影像的應用程式。它支援本機檔案與原始影像資料,適用於各種使用情境。

適用情境

  • 儲存擷取的螢幕截圖
  • 儲存產生的藝術作品
  • 匯出使用者建立的影像
  • 從應用內容中分享圖片
  • 儲存下載的媒體

主要特色

  • 簡單儲存 API
  • 支援 Android 和 iOS
  • 處理位元資料和檔案路徑
  • iOS 上需要 Info.plist 配置
  • 跨平台相容性

適合對象

  • 影像編輯應用
  • 社交媒體分享工具
  • 照片生成工具
  • 使用者產生內容的應用程式
  • 需要離線圖像存儲的工具

使用建議

  • iOS 需要 Info.plist 條目
  • 權限可能因平台而異
  • 大檔案可能會影響效能
  • 有限的自定選項
  • 無內建進度回饋

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

image_gallery_saver

Build Status pub package license

We use the image_picker plugin to select images from the Android and iOS image library, but it can't save images to the gallery. This plugin can provide this feature.

Usage

To use this plugin, add image_gallery_saver as a dependency in your pubspec.yaml file. For example:

dependencies:
  image_gallery_saver: '^2.0.3'

iOS

Your project need create with swift. Add the following keys to your Info.plist file, located in /ios/Runner/Info.plist:

  • NSPhotoLibraryAddUsageDescription - describe why your app needs permission for the photo library. This is called Privacy - Photo Library Additions Usage Description in the visual editor

Android

You need to ask for storage permission to save an image to the gallery. You can handle the storage permission using flutter_permission_handler. In Android version 10, Open the manifest file and add this line to your application tag

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

Example

Saving an image from the internet, quality and name is option

  _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 ImageGallerySaver.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 ImageGallerySaver.saveImage(
        Uint8List.fromList(response.data),
        quality: 60,
        name: "hello");
    print(result);
  }

Saving file(ig: video/gif/others) from the internet

  _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 ImageGallerySaver.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 ImageGallerySaver.saveFile(savePath);
    print(result);
  }

所屬分類

原始碼儲存庫

使用此套件的專案