搜索分类、插件与代码仓

插件详情v4.12.0

image

Dart 图像库为服务器和 Web 应用程序提供了加载、操作和保存各种图像文件格式的图像的能力。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
895万
喜欢数
1760
Pub 分数
160

安装插件

flutter pub add image

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Dart 图像库使服务器和 Web 应用程序能够加载、操作和保存多种格式的图像。它支持常见的操作,如调整大小、裁剪、颜色调整和格式转换,使其非常适合在不依赖原生平台工具的情况下进行图像处理任务。该库轻量且专为在 Android、iOS、Web、macOS、Windows 和 Linux 上的 Flutter 应用中使用而设计。它特别适用于后端图像转换或动态生成缩略图。

适合场景

  • 图像调整大小和裁剪
  • 缩略图生成
  • 图像格式转换
  • 服务器端图像处理
  • 网页应用中的动态图像操作

主要特点

  • 支持多种图像格式
  • 跨平台兼容性
  • 轻便且快速
  • 内置图像滤镜
  • 可扩展的图像处理流水线

适合对象

  • 后端图像处理
  • 基于网络的图像工具
  • 需要图像处理的Flutter应用
  • 自动化图像工作流程
  • 开发图像编辑功能的开发者

使用建议

  • 未针对实时UI渲染进行优化
  • 对高级图像效果的支持有限
  • 需要手动处理大文件
  • 无内置缓存
  • 最适合非交互式图像任务

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Dart Image Library

Dart CI pub package

Overview

The Dart Image Library provides the ability to load, save, and manipulate images in a variety of image file formats.

The library can be used with both dart:io and dart:html, for command-line, Flutter, and web applications.

NOTE: 4.0 is a major revision from the previous version of the library.

Documentation

Supported Image Formats

Read/Write

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

Read Only

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

Write Only

  • CUR

Examples

Create an image, set pixel values, save it to a PNG.

import 'dart:io';
import 'package:image/image.dart' as img;
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 (var pixel in image) {
    // Set the pixels red value to its x position value, creating a gradient.
    pixel..r = pixel.x
    // Set the pixels green value to its y position value.
    ..g = pixel.y;
  }
  // Encode the resulting image to the PNG image format.
  final png = img.encodePng(image);
  // Write the PNG formatted data to a file.
  await File('image.png').writeAsBytes(png);
}

To asynchronously load an image file, resize it, and save it as a thumbnail:

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

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 and a height that maintains the aspect ratio of the original. 
    ..copyResize(width: 64)
    // Write the image to a PNG file (determined by the suffix of the file path). 
    ..writeToFile('thumbnail.png');
  // On platforms that support Isolates, execute the image commands asynchronously on an isolate thread.
  // Otherwise, the commands will be executed synchronously.
  await cmd.executeThread();
}

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

所在榜单