90도 회전을 지원하는 이미지 자르기용 플러터 위젯으로 모바일, 웹, 데스크톱 플랫폼에서 사용하기 위해 설계되었습니다. 이미지 자르기 영역을 선택하고 조정할 수 있는 직관적인 인터페이스를 제공하여 프로필 사진 편집, 사진 처리 및 콘텐츠 제작 워크플로우에 적합합니다. 이 패키지는 가볍고 기존 플러터 애플리케이션에 원활하게 통합됩니다.
사용 사례
프로필 사진 자르기
사진 편집 도구
콘텐츠 생성 앱
이미지 전처리
사용자 아바타 관리
주요 기능
90도 이미지 회전
크로스 플랫폼 호환성
직관적인 드래그 앤 드롭 자르기
사용자 지정 가능한 자르기 비율
내장된 저장/내보내기 기능
적합한 대상
이미지 편집 기능을 구축하는 개발자
사용자가 업로드한 이미지 조작이 필요한 앱
다중 플랫폼 Flutter 프로젝트
간단하지만 효과적인 자르기 솔루션
고려 사항
자르기 전에 이미지를 로드해야 합니다
직사각형 자르기 형태로 제한
필터와 같은 고급 편집 도구 없음
외부 이미지 로딩 라이브러리에 의존합니다
일부 플랫폼에서는 파일 액세스를 위해 추가 권한이 필요할 수 있습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Crop Image
An image cropper widget. It provides the usual user experience of classic mobile and desktop
image croppers but, as it's written completely in Dart, it doesn't depend on any mobile package.
Consequently, it runs on all platforms supported by Flutter: mobile, web and desktop alike.
The appearance of the crop rectangle can be customized.
final controller = CropController(
/// If not specified, [aspectRatio] will not be enforced.
aspectRatio: 1,
/// Specify in percentages (1 means full width and height). Defaults to the full image.
defaultCrop: Rect.fromLTRB(0.1, 0.1, 0.9, 0.9),
);
CropImage(
/// Only needed if you expect to make use of its functionality like setting initial values of/// [aspectRatio] and [defaultCrop].
controller: controller,
/// The image to be cropped. Use [Image.file] or [Image.network] or any other [Image].
image: Image.asset('...'),
/// The crop grid color of the outer lines. Defaults to 70% white.
gridColor: Colors.white,
/// The crop grid color of the inner lines. Defaults to [gridColor].
gridInnerColor: Colors.white,
/// The crop grid color of the corner lines. Defaults to [gridColor].
gridCornerColor: Colors.white,
/// The size of the corner of the crop grid. Defaults to 25.
gridCornerSize: 50,
/// The offset of the corner handles from the crop grid edges. /// Positive values move corners outside. Defaults to 0.
cornerOffset: 10,
/// Whether to display the corners. Defaults to true.
showCorners: true,
/// The width of the crop grid thin lines. Defaults to 2.
gridThinWidth: 3,
/// The width of the crop grid thick lines. Defaults to 5.
gridThickWidth: 6,
/// The crop grid scrim (outside area overlay) color. Defaults to 54% black.
scrimColor: Colors.grey.withOpacity(0.5),
/// True: Always show third lines of the crop grid./// False: third lines are only displayed while the user manipulates the grid (default).
alwaysShowThirdLines: true,
/// Event called when the user changes the crop rectangle./// The passed [Rect] is normalized between 0 and 1.
onCrop: (rect) => print(rect),
/// The minimum pixel size the crop rectangle can be shrunk to. Defaults to 100.
minimumImageSize: 50,
/// The maximum pixel size the crop rectangle can be grown to. Defaults to infinity./// You can constrain the crop rectangle to a fixed size by setting/// both [minimumImageSize] and [maximumImageSize] to the same value (the width) and using/// the [aspectRatio] of the controller to force the other dimension (width / height)./// Doing so disables the display of the corners.
maximumImageSize: 2000;
);
Setting up
Using a controller is optional, if you don't provide your own, the widget will create one and use it internally.
Without a controller, you can handle the onCrop event and keep track of the changing crop selection of the user.
When using a controller, you don't need to use onCrop, you can simply read out the crop values any time,
also converted to pixels rather than percentage.
Initial values for aspectRatio and defaultCrop can be provided on the controller.
Note that if an aspectRatio was specified, all crop rectangles will be adjusted automatically to fit the
required aspect ratio.
Fixed crop size
You can constrain the crop rectangle to a fixed size by setting both minimumImageSize and maximumImageSize
to the same value (the width) and using the aspectRatio of the controller to force the other dimension (width / height).
Doing so disables the display of the corners.
Rotation
You can set the rotation of the crop rectangle to a specific orientation using the provided CropRotation values:
The final crop rectangle decided by the user can be used in various ways. The base output of the widget
is the crop rectangle in relative terms, all four values of the Rect normalized to between 0 and 1
(1 meaning full width and height), so basically in percentage. The controller also has a cropSize property
that maps the crop rectangle to the actual pixels of the bitmap.
Rect finalCropRelative = controller.crop;
Rect finalCropPixels = controller.cropSize;
The widget does not crop the original bitmap directly but its CropController provides two convenience functions
to do so if required:
If you want to create an Image with additional settings (eg. different Image.fit), replicate the functionality of
croppedImage() for yourself. You can use the UiImageProvider image provider exposed from the package.
Creating a file
If you want to save the cropped ui.Image to a file, this operation is not specific to this plugin. Use the existing functions
of ui.Image and File:
data = await bitmap.toByteData(format: ImageByteFormat.png);
bytes = data!.buffer.asUint8List();
file.writeAsBytes(bytes, flush);
Known problems
croppedBitmap() – and consequently, croppedImage() – result in an exception on Flutter Web with the HTML web renderer.
The culprit is Picture.toImage() that doesn't work with it (see https://github.com/flutter/engine/pull/20750).
Consider using CanvasKit for the web renderer (which is much better than HTML, anyway).
Support
If you like this package, please consider supporting it.