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

套件詳情v1.0.1

jpeg_encode

一個極簡的JPEG編碼器。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
4900
喜歡數
19
Pub 分數
120

安裝套件

flutter pub add jpeg_encode

套件介紹

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

一個為 Flutter 設計的極簡 JPEG 編碼器,允許開發者在多個平台壓縮並編碼圖像為 JPEG 格式。以簡單為核心設計,提供輕量級解決方案,將影像資料轉換為 JPEG 格式,無需複雜依賴。適用於需要高效影像壓縮或以廣泛支援的格式儲存影像的應用程式。此套件支援 Android、iOS、Web、macOS、Windows 及 Linux,確保廣泛相容性。在檔案大小縮減至關重要的情境中尤為實用。

適用情境

  • 行動應用中的影像壓縮
  • 將捕獲的照片儲存為JPEG
  • 減小圖像檔案大小以用於網路上傳
  • 圖像資產的批處理
  • 將JPEG編碼整合到跨平台應用程式中

主要特色

  • 輕量且簡潔的 API
  • 跨平台支援
  • 從圖像數據進行簡單編碼
  • 高效壓縮
  • 無外部原生依賴

適合對象

  • 需要基本JPEG編碼的開發人員
  • 專注於圖像優化的應用程式
  • 跨平台多媒體應用
  • 需要小體積編碼器的項目

使用建議

  • 僅限JPEG格式
  • 沒有像品質調節之類的進階編碼選項
  • 不適合複雜的影像處理
  • 取決於底層平台的影像處理能力

原始 README

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

JPEG encoder

pub package

Skia, the engine behind dart:ui has no support for JPEG, only PNG and raw RGBA. And the source code comments make it clear that they don't intend to add any more formats, those should be left to external packages.

While there are packages that offer full support for image manipulation, many a time we don't need that, just to be able to convert a file to JPG for use outside of our app, maybe to send it to the web. This package does that and nothing else. It's a minimalistic JPEG encoder that doesn't offer any extra functionality but to create the simplest JPEG file. Not necessarily the best or most compressed one, although it's fairly good, nonetheless.

The code is just a straight Dart port of an existing implementation of Jon Olick from https://www.jonolick.com/code.html.

How to use

Let's suppose you have a dart:ui Image from somewhere, maybe you converted from an incoming image:

import "dart:ui" as ui;

Uint8List bytes;
final codec = await ui.instantiateImageCodec(bytes);
final frame = await codec.getNextFrame();
final image = frame.image;

And you want to convert it to JPG (quality is between 0 and 100, as usual):

final data = await image.toByteData(format: skia.ImageByteFormat.rawRgba);
final jpg = JpegEncoder().compress(data!.buffer.asUint8List(), image.width, image.height, 90);

In other words, the pixel array is expected to be in row major format (all columns of first row, then of the second row, etc), four bytes for each pixel: R, G, B and A. Alpha is ignored but the byte is expected to be there. Consequently, the length of the array has to be width * height * 4.

Before you ask, saving in Flutter is as simple as:

File(path).writeAsBytesSync(jpg); // or
await File(path).writeAsBytes(jpg);

Support

If you like this package, please consider supporting it.

Buy Me A Book

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。