패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.1

jpeg_encode

최소한의 JPEG 인코더입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
4.9천
좋아요
19
Pub 점수
120

패키지 설치

flutter pub add jpeg_encode

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

다양한 플랫폼에서 이미지를 JPEG 형식으로 압축하고 인코딩할 수 있는 Flutter용 최소한의 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

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.