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

custom_image_crop 封面
套件詳情v0.1.1

custom_image_crop

一個可自訂的影像裁切器。您可以透過觸控動作或控制器進行旋轉、縮放和移動。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.2萬
喜歡數
89
Pub 分數
150

安裝套件

flutter pub add custom_image_crop

套件介紹

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

一個高度可自訂的 Flutter 圖像裁切工具,支援使用者透過直覺的手勢或控制器旋轉、縮放和移動影像。專為跨多個平台的無縫整合而設計,提供對裁切體驗的細緻控制。適用於需要進階影像處理功能且具備回應式與互動式介面的應用程式。此套件支援 Android、iOS、Web、macOS、Windows 與 Linux,確保廣泛的相容性。

適用情境

  • 在照片應用中自定義圖像編輯
  • 使用者個人檔案圖片裁剪
  • 互動式圖像選擇工具
  • 設計應用程式中的動態圖像調整大小
  • 機器學習工作流程中的影像預處理

主要特色

  • 基於手勢的旋轉、縮放和平移
  • 控制器驅動的圖像操作
  • 跨平台支援
  • 高度可定制的 UI 組件
  • 裁剪時的即時預覽
  • 適用於所有螢幕尺寸的響應式設計

適合對象

  • 開發影像編輯功能的開發者
  • 需要精確圖像裁剪的應用程式
  • 跨平台圖像編輯工具
  • 帶有圖像處理的互動式使用者介面
  • 原型設計高級圖像編輯工作流程

使用建議

  • 需要仔細處理大圖像以避免效能問題
  • 可能需要額外的狀態管理來處理複雜用例
  • 初始設定需要了解手勢檢測器和控制器
  • 未針對無需下採樣的高解析度影像進行優化
  • 內建預設有限;需自訂特定的作物比例

原始 README

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

custom_image_crop

An Image cropper that is customizable

pub package Build Status Coverage Status MIT license

customcropcircle customcropsquare customcropcircle

CustomImageCrop

CustomImageCrop(
  cropController: controller,
  image: const AssetImage('assets/test.png'),
),

You can provide the image using any Imageprovider.

Parameters

required image

The image that needs to be cropped

cropController

The controller used to adjust the image and crop it.

overlayColor

The color above the image that will be cropped

backgroundColor

The color behind the image. This color will also be used when there are gaps/empty space after the cropping

shape

The shape of the cropping path.

maskShape

The shape of the UI masking.

cropPercentage

How big the crop should be in regards to the width and height available to the cropping widget.

drawPath

How the border of the crop should be painted. default DottedCropPathPainter.drawPath and SolidCropPathPainter.drawPath are provided, but you can create/provide any CustomPaint.

pathPaint

Custom painting for the crop area border style.

canRotate

Whether to allow the image to be rotated.

customProgressIndicator

Custom widget for progress indicator.

ratio

Ratio of the cropping area. If shape`` is set to CustomCropShape.Ratio, this property is required. For example, to create a square crop area, use [Ratio(width: 1, height: 1). To create a rectangular crop area with a 16:9 aspect ratio, use [Ratio(width: 16, height: 9)`.

borderRadius

The radius for rounded corners of the cropping area.

forceInsideCropArea

Whether image area must cover clip path.

Controller Methods

addTransition

void addTransition(CropImageData transition)

Add the position, angle and scale to the current state. This can be used to adjust the image with sliders, buttons, etc.

setData

void setData(CropImageData data)

Set the position, angle and scale to the specified values. This can be used to center the image by pressing a button for example.

reset

void reset()

Reset the image to its default state

onCropImage

Future<MemoryImage> onCropImage()

Crops the image in its current state, this will return a MemoryImage that contains the cropped image

Example

See example/lib

class MyHomePage extends StatefulWidget {
  final String title;

  MyHomePage({
    required this.title,
    Key? key,
  }) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late CustomImageCropController controller;

  @override
  void initState() {
    super.initState();
    controller = CustomImageCropController();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        brightness: Brightness.dark,
      ),
      body: Column(
        children: [
          Expanded(
            child: CustomImageCrop(
              cropController: controller,
              image: const AssetImage('assets/test.png'), // Any Imageprovider will work, try with a NetworkImage for example...
            ),
          ),
          Row(
            children: [
              IconButton(icon: const Icon(Icons.refresh), onPressed: controller.reset),
              IconButton(icon: const Icon(Icons.zoom_in), onPressed: () => controller.addTransition(CropImageData(scale: 1.33))),
              IconButton(icon: const Icon(Icons.zoom_out), onPressed: () => controller.addTransition(CropImageData(scale: 0.75))),
              IconButton(icon: const Icon(Icons.rotate_left), onPressed: () => controller.addTransition(CropImageData(angle: -pi / 4))),
              IconButton(icon: const Icon(Icons.rotate_right), onPressed: () => controller.addTransition(CropImageData(angle: pi / 4))),
              IconButton(
                icon: const Icon(Icons.crop),
                onPressed: () async {
                  final image = await controller.onCropImage();
                  if (image != null) {
                    Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => ResultScreen(image: image)));
                  }
                },
              ),
            ],
          ),
          SizedBox(height: MediaQuery.of(context).padding.bottom),
        ],
      ),
    );
  }
}

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。