パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細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として保存する
  • Webアップロード用に画像ファイルサイズを小さくする
  • 画像アセットのバッチ処理
  • クロスプラットフォームアプリへの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

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。