使用Nuget插件AnalysisImagePixel的一个示例
AnalysisImagePixel插件是基于.net standard框架开发的, 因此可用于UWP/Net Framework(4.6.x+)框架的APP
将图片转换为卡通风格,忽略面部细节和增强对比度。
下面是一些效果图:
PM->Install-Package AnalysisImagePixel
使用过程就是读取图片像素,然后调用返回像素结果。
var pixels = await bitmapDecoder.GetPixelDataAsync();
//----------------------------------------------------------
MainFunction main = new MainFunction();
main.MsgReporter = this;// optional
var resultPixels=await main.Run(pixels.DetachPixelData(), (int)bitmapDecoder.PixelWidth, (int)bitmapDecoder.PixelHeight);
using (var stream= await file.OpenReadAsync())
{
_bitmap = new BitmapImage();
await _bitmap.SetSourceAsync(stream);
Image1.Source = _bitmap;
//
BitmapDecoder bitmapDecoder = await BitmapDecoder.CreateAsync(stream);
//
var pixels = await bitmapDecoder.GetPixelDataAsync();
//----------------------------------------------------------
MainFunction main = new MainFunction();
main.MsgReporter = this;// optional
var resultPixels=await main.Run(pixels.DetachPixelData(), (int)bitmapDecoder.PixelWidth, (int)bitmapDecoder.PixelHeight);
//
using (var ms = new InMemoryRandomAccessStream())
{
float devicedpi = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi;
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, ms);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore,bitmapDecoder.PixelWidth,bitmapDecoder.PixelHeight, devicedpi, devicedpi, resultPixels);
await encoder.FlushAsync();
var _bitmap2 = new BitmapImage();
await _bitmap2.SetSourceAsync(ms);
Image2.Source = _bitmap2;
}
//--
}