image

brendan-duncanMIT活跃维护

Dart 图像处理库,支持在 Dart 和 Flutter 中打开、编辑并保存 JPEG、PNG、WebP 等多种格式图片,无需依赖原生扩展。

Dart Image Library for opening, manipulating, and saving various different image file formats.

暂无版本1,266star308fork同步于 2026-11-10 17:51 UTC

怎么上手

由 README 提炼,执行前请确认
dart pub add image
硬件要求按 README 说明

README 未说明,纯 Dart 实现无原生依赖,可在 Dart 支持的任意平台运行

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

纯 Dart 图像处理库,无需原生依赖,跨命令行、服务端、Flutter 和 Web 读写与编辑图片

Dart 图像处理库,支持在 Dart 和 Flutter 中打开、编辑并保存 JPEG、PNG、WebP 等多种格式图片,无需依赖原生扩展。

核心能力

  • 解码编码 JPEG、PNG、GIF、WebP 等格式,支持动图
  • 提供缩放、裁剪、旋转、翻转等几何变换
  • 内置数十种滤镜、颜色量化与抖动
  • 支持绘制形状、文字和叠加图片
  • Command API 可在独立 isolate 中执行图像处理

容易踩的坑

decodeJpg 等解码函数可能返回 null 或抛出 ImageException,需判空处理;Command API 在 Web 等不支持 isolate 的平台会退回主线程执行

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Dart Image Library

    Dart CI pub package

    Overview

    The Dart Image Library loads, saves and manipulates images in a variety of image file formats.

    It's written in pure Dart with no native dependencies, so it works everywhere Dart does: command-line apps, servers, Flutter on every platform, and the web.

    Features include:

    Documentation

    Supported Image Formats

    Read/Write

    • JPEG
    • PNG / Animated PNG
    • GIF / Animated GIF
    • WebP / Animated WebP (lossless and lossy)
    • BMP
    • TIFF
    • TGA
    • ICO
    • PVR

    Read Only

    • PSD
    • EXR
    • PNM (PBM, PGM, PPM)

    Write Only

    • CUR

    Getting started

    dart pub add image
    
    import 'package:image/image.dart' as img;
    

    Examples

    Create an image, set pixel values, and save it as a PNG:

    import 'dart:io';
    import 'package:image/image.dart' as img;
    
    Future<void> main() async {
      // Create a 256x256 8-bit (default) RGB (default) image.
      final image = img.Image(width: 256, height: 256);
      // Iterate over its pixels.
      for (final pixel in image) {
        pixel
          // Set the red channel to the x position, creating a gradient.
          ..r = pixel.x
          // Set the green channel to the y position.
          ..g = pixel.y;
      }
      // Encode the image to the PNG format.
      final png = img.encodePng(image);
      // Write the PNG data to a file.
      await File('image.png').writeAsBytes(png);
    }
    

    Load a JPEG, make a thumbnail, and save it:

    import 'dart:io';
    import 'package:image/image.dart' as img;
    
    Future<void> main() async {
      final bytes = await File('photo.jpg').readAsBytes();
      // Decode the JPEG. This returns null, or throws an ImageException, if the
      // data isn't a valid JPEG.
      final image = img.decodeJpg(bytes);
      if (image == null) {
        return;
      }
      // Resize to 120 pixels wide, keeping the aspect ratio. The EXIF orientation
      // of the photo is applied.
      final thumbnail = img.copyResize(image, width: 120);
      // Encode as a JPEG and save it.
      await File('thumbnail.jpg').writeAsBytes(img.encodeJpg(thumbnail, quality: 85));
    }
    

    Do the same work in a separate isolate with the Command API, so it doesn't block the main isolate:

    import 'package:image/image.dart' as img;
    
    Future<void> main(List<String> args) async {
      final path = args.isNotEmpty ? args[0] : 'test.png';
      final cmd = img.Command()
        // Decode the image file at the given path.
        ..decodeImageFile(path)
        // Resize the image to a width of 64 pixels, keeping the aspect ratio.
        ..copyResize(width: 64)
        // Write the image to a PNG file (the format comes from the file extension).
        ..writeToFile('thumbnail.png');
      // On platforms that support isolates, execute the commands on a separate
      // isolate. Otherwise (on the web), they run on the main thread.
      await cmd.executeThread();
    }
    

    See the tutorial for more.