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

套件詳情v0.0.6

image_crop_widget

一個用於裁剪影像的 Flutter 小工具。此小工具完全以 Dart 寫成,依賴性極少。

近 30 天下載
28
喜歡數
9
Pub 分數
40

安裝套件

flutter pub add image_crop_widget

套件介紹

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

一個專為在應用內直接裁剪影像而設計的 Flutter 小部件。完全以 Dart 編寫,依賴極少,提供輕量且高效能的影像處理解決方案。該小部件提供直覺的控制功能,用於選擇和調整裁剪區域,非常適合用於頭像編輯或影像預處理。它可無縫整合至 Flutter 專案中,並支援不同螢幕尺寸的響應式設計。

適用情境

  • 個人檔案圖片裁剪
  • 上傳前的圖像預處理
  • 使用者產生內容編輯
  • 應用中的照片編輯工具
  • 自定義圖像選擇工作流

主要特色

  • 純 Dart 實現
  • 最小依賴
  • 響應式使用者介面
  • 直觀的拖放裁切控制項
  • 與 Flutter 項目的輕鬆整合

適合對象

  • 開發圖像密集型應用的開發者
  • 需要用戶圖像裁剪的應用
  • 優先考慮輕量級依賴項的專案
  • 前端開發人員尋求簡單解決方案
  • 行動應用程式功能,帶有影像編輯需求

使用建議

  • 僅限基本裁剪功能
  • 無內建影像濾鏡或增強功能
  • 需要手動處理裁剪後的圖像輸出
  • 未針對非常大的圖像進行優化
  • 不支援同時多個裁切區域

原始 README

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

image_crop_widget

A Flutter widget to crop images. The widget is completely written in Dart and has minimal dependencies.

The widget displays the image within the given layout space. On top of the image a transparent rectangular overlay, with handles on each corner, is drawn. The overlay handles can be dragged by touch to adjust the cropping area.

Example

By calling the cropImage() method on the widget's state object, the image area that is marked by the overlay is returned as a new image object.

To acquire the widget's state you can use a GlobalKey object.

Example:

import 'dart:ui'; // This imports the 'Image' class.

final key = GlobalKey<ImageCropState>();
Image imageObject = ...

...

ImageCrop(key: key, image: imageObject) // This could be used inside a  build method.

...
await key.currentState.rotateImage(); // Rotate the image be 90° clockwise.
final cropedImage = await key.currentState.cropImage(); // This could be used inside a 'onPress' handler method.

How to create an image object

The Image class from dart:ui is typically not instantiated directly. Instead, you could convert your image data into a Uint8List and instantiate the image like this:

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

How to display an image object

The Image object can be displayed with the Flutter Image widget. One way to do this, is by converting the image into a Uint8List and pass it into the widget's memory constructor. Please note, that the widget is not the same Image class as the image object itself.

final cropedImage = await key.currentState.cropImage();
final byte = await cropedImage.toByteData(format: ui.ImageByteFormat.png);
final byteList = byte.buffer.asUint8List();

Image.memory(byteList)

How to persist an image object

The Image object can be persisted into a file or a database. To do this, you can convert the image object into a Uint8List and write it into a File or your database object.

final cropedImage = await key.currentState.cropImage();
final byte = await cropedImage.toByteData(format: ui.ImageByteFormat.png);
final byteList = byte.buffer.asUint8List();

final imageFile = File("Some path and filename"); // You can use the path_provider package to locate the right path.
final result = await imageFile.writeAsBytes(byteList);

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。