This plugin will enable you to manipulate(resize,crop,rotate) and filter(monochrome) a image(png,jpg).
Install-Package Xamarin.Plugin.ImageEdit
Platform Support
Platform | Supported | Version |
---|---|---|
Xamarin.iOS | Yes | iOS 9+ |
Xamarin.Android | Yes | API 22+ |
Windows 10 UWP | No | |
Xamarin.Mac | No |
Image crop and rotate and resize and get png data.
using (var image = await CrossImageEdit.Current.CreateImageAsync(imageByteArray)) {
var croped = await Task.Run(() =>
image.Crop(10, 20, 250, 100)
.Rotate(180)
.Resize(100, 0)
.ToPng()
);
}
//View model constructor
public ViewModel(IImageEdit imageEdit){
using (var image = await imageEdit.CreateImageAsync(imageByteArray)) {
var croped = await Task.Run(() =>
image.Crop(10, 20, 250, 100)
.Rotate(180)
.Resize(100, 0)
.ToPng()
);
}
}
//on platform
public class iOSInitializer : IPlatformInitializer
{
public void RegisterTypes(IUnityContainer container)
{
container.RegisterType<IImageEdit,ImageEdit>();
}
}
https://github.com/muak/PanPinchSample
movie https://twitter.com/muak_x/status/837266085405573120
//from byte[]
var image = await CrossImageEdit.Current.CreateImageAsync(imageByteArray);
//from stream
var image = await CrossImageEdit.Current.CreateImageAsync(imageStream);
It is able to manipulate a image using this object.
var width = 200;
var height = 150;
image.Resize(width, height);
image.Resize(width, 0); //auto height
image.Resize(0, height); //auto width
image.Resize(50); //specify max length of long side. other side auto size.
var x = 10;
var y = 10;
var width = 50;
var height = 50;
image.Crop(10, 10, 50, 50);
var degree = 90; // 0-360;
image.Rotate(degree);
The image will convert to monochrome.
image.ToMonochrome();
var pngBytes = image.ToPng();
var jpgBytes = image.ToJpeg(90); // quality(0-100)
Get image ARGB infomation.
for example when 0xFF00F090
A | R | G | B |
---|---|---|---|
FF | 00 | F0 | 90 |
var pixels = image.ToArgbPixels();
var pixel = pixels[10];
var r = pixel & 0x00FF0000 >> 16; //Get R
var g = pixel & 0x0000FF00 >> 8; //Get G
var b = pixel & 0x000000FF; //Get B
Get native image on platform. if platform is iOS, return UIImage; otherwise return Bitmap.
MIT Licensed.