搜尋分類、套件與程式碼儲存庫

套件詳情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 項

原始碼儲存庫

使用此套件的專案

所在榜單