XDev.Maui.ManualCrop
0.0.1-alpha010
See the version list below for details.
dotnet add package XDev.Maui.ManualCrop --version 0.0.1-alpha010
NuGet\Install-Package XDev.Maui.ManualCrop -Version 0.0.1-alpha010
<PackageReference Include="XDev.Maui.ManualCrop" Version="0.0.1-alpha010" />
paket add XDev.Maui.ManualCrop --version 0.0.1-alpha010
#r "nuget: XDev.Maui.ManualCrop, 0.0.1-alpha010"
// Install XDev.Maui.ManualCrop as a Cake Addin #addin nuget:?package=XDev.Maui.ManualCrop&version=0.0.1-alpha010&prerelease // Install XDev.Maui.ManualCrop as a Cake Tool #tool nuget:?package=XDev.Maui.ManualCrop&version=0.0.1-alpha010&prerelease
Maui.ManualCropApp
Contributions are welcome!
This is a portable image cropper control for Maui. Source: https://xdevapps.visualstudio.com/_git/XDev.Maui.ManualCrop
Reference code: https://github.com/dotnet/maui-samples/blob/main/8.0/SkiaSharp/PhotoPuzzle/PhotoPuzzle/Pages/CropPhotoPage.xaml.cs
MS provided sample above is refactored into a lib for use in any Maui app.
Most XForms and Maui image cropping libs out there only support Android/iOS with lots of native dependencies. If those work for you, then you can still use them, but this lib is smaller/lighter and less complicated to maintain and consume.
Screen-Shots
- More options coming soon, submit contributions!
Supported platforms
All Maui platforms
* Android
* iOS
* Windows
* Mac
Usage
The simplest way to use this lib is to:
Initialize the library
builder.UseMauiApp<App>()
.UseImageCropper();
And then show the cropping window
in your app code, show the cropper by passing an ImageSource
to the ImageCropperService
,
and save the cropped image to the app data-cache.
async void OnClicked(object sender, EventArgs args)
{
FileResult? photo = await MediaPicker.Default.PickPhotoAsync();
var imageSource = new FileImageSource()
{
File = photo.FullPath,
};
// resolve service from DI container and show the CropperPage
var result = await IPlatformApplication.Current
.Services
.GetRequiredService<IImageCropperService>()
.ShowAsync(imageSource);
if (result.Successful)
{
var newfile = await result.SaveToCacheAsync(photo.FileName);
}
}
Options for the default CropperPage modal
There are many options for customizing the pre-baked UI. You can access them via the ImageCropperConfig
class and pass them when displaying the modal.
If not provided, a default is used. Either the default, or that last config provided is used for calls that do not supply a new config.
var result = await _imageCropperService.ShowAsync((SKBitmapImageSource)bitmap,
new ImageCropperConfig()
{
BackgroundColor = Colors.White,
CroppingCornerStrokeColor = Colors.Green,
CroppingEdgeStrokeColor = Colors.Red,
OverlayColor = Colors.AliceBlue.WithAlpha(0.7f),
Title = "I am title",
TitleTextColor = Colors.Green,
TitleFontSize = 14,
CancelText = "CANCEL",
CancelTextColor = Colors.DarkRed,
CancelFontSize = 12,
SaveText = "SAVE",
SaveTextColor = Colors.DarkGreen,
SaveFontSize = 12,
CenterRadius = 25f,
});
or you can override the default confiuration during initialization
builder.UseMauiApp<App>()
.UseImageCropper(croppingViewConfig:new ImageCropperConfig()
{
BackgroundColor = Colors.White,
CroppingCornerStrokeColor = Colors.Green,
});
Advanced usage
The CropResult
object provides an in memory copy to the cropped Bitmap image: CropResult.CroppedImage
You probably want to convert to some compressed image format.
CropResult.GetStreamAsync(SKEncodedImageFormat format = SKEncodedImageFormat.Png)
supports Png by default, but also Jpeg and Bitmap.
This stream is useful if you wish to upload directly to remote storage without saving a local copy, or do any other manipulation.
Also, you can use PhotCropperCanvasView
to embed the cropper UI in a custom page in your app for a fully customized look and feel.
How to test iOS:
- use iOS sim (easiest, use ctrl-click to test pinch/gestures)
- on an iphone: update info.plist file in test app using your own wildcard or other dev-provisioning profile:
<key>CFBundleIdentifier</key>
<string>com.[your-provisioning-profile-here].maui.manualcropapp</string>
some possible useful refs
https://github.com/mono/SkiaSharp/issues/804 https://github.com/HeikkiDev/XFManualCropControl/blob/master/XFManualCropApp/XFManualCropApp/Controls/ManualCropView.cs
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-android34.0 is compatible. net8.0-browser was computed. net8.0-ios was computed. net8.0-ios18.0 is compatible. net8.0-maccatalyst was computed. net8.0-maccatalyst18.0 is compatible. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net8.0-windows10.0.19041 is compatible. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.Maui.Controls (>= 8.0.72)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.72)
- SkiaSharp.Views.Maui.Controls (>= 2.88.8)
-
net8.0-android34.0
- Microsoft.Maui.Controls (>= 8.0.72)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.72)
- SkiaSharp.Views.Maui.Controls (>= 2.88.8)
-
net8.0-ios18.0
- Microsoft.Maui.Controls (>= 8.0.72)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.72)
- SkiaSharp.Views.Maui.Controls (>= 2.88.8)
-
net8.0-maccatalyst18.0
- Microsoft.Maui.Controls (>= 8.0.72)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.72)
- SkiaSharp.Views.Maui.Controls (>= 2.88.8)
-
net8.0-windows10.0.19041
- Microsoft.Maui.Controls (>= 8.0.72)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.72)
- SkiaSharp.Views.Maui.Controls (>= 2.88.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.1-alpha012 | 0 | 2/5/2025 |
0.0.1-alpha011 | 65 | 2/4/2025 |
0.0.1-alpha010 | 40 | 2/3/2025 |
0.0.1-alpha009 | 50 | 2/2/2025 |
0.0.1-alpha008 | 40 | 2/1/2025 |
0.0.1-alpha007 | 34 | 1/30/2025 |
0.0.1-alpha006 | 31 | 1/30/2025 |
0.0.1-alpha005 | 32 | 1/30/2025 |
0.0.1-alpha004 | 9 | 1/29/2025 |
0.0.1-alpha003 | 32 | 1/28/2025 |
0.0.1-alpha002 | 27 | 1/27/2025 |
initial release