我一直在寻找解决方案,但还没有找到。我的应用程序的功能之一是加载图像,然后更改其形状 - 例如,我加载正常的矩形图像,然后有 2-3 个按钮 - 将图像更改为圆形、三角形或其他形状。像这样的东西甚至可以用位图吗?我发现了很多关于诺基亚成像 SDK 的有趣的东西,但我发现的所有形状都是LensBlurEffect,这并不是我所需要的。
如果有人能指出我正确的方向,我将不胜感激!
提前感谢您的帮助!
最好的问候,罗马
我一直在寻找解决方案,但还没有找到。我的应用程序的功能之一是加载图像,然后更改其形状 - 例如,我加载正常的矩形图像,然后有 2-3 个按钮 - 将图像更改为圆形、三角形或其他形状。像这样的东西甚至可以用位图吗?我发现了很多关于诺基亚成像 SDK 的有趣的东西,但我发现的所有形状都是LensBlurEffect,这并不是我所需要的。
如果有人能指出我正确的方向,我将不胜感激!
提前感谢您的帮助!
最好的问候,罗马
好吧,位图总是矩形的,对此您无能为力。
您可以做的是使一些像素透明,从而使位图显示为不同的形状。
使用 Nokia Imaging SDK 的一种方法是使用 BlendFilter 在原始图像上混合透明图像(我建议只使用 ColorImageSource)。您可以提供不同的蒙版来创建不同的“形状”。
我正在研究使用诺基亚成像 SDK 绘制形状的过滤器。为了解决您的问题,我创建了使用 Nokia Imaging SDK 的混合滤镜和我的自定义形状滤镜的示例项目。
实际上,您可以对 David 所指的形状图像执行相同的操作(背景为黑色,前景为白色),而不是使用我的自定义过滤器(示例代码上方的 EllipseShapeFilter)。
这是示例代码;
var ellipseImage = new WriteableBitmap(1024, 768);
Rect origin = new Rect(new Point(512, 384), new Size(512, 384));
uint white = 0xff000000 | (255 << 16) | (255 << 8) | 255;
var image = LoadFromResources(new Uri(@"/BlendImageSample;component/Assets/Sample.jpg", UriKind.Relative));
using (var ellipseSource = new BitmapImageSource(ellipseImage.AsBitmap()))
using (var ellipse = new EllipseShapeFilter(ellipseSource, white, origin))
{
ellipseImage = await new WriteableBitmapRenderer(ellipse, ellipseImage).RenderAsync();
}
ImageViewer.Source = ellipseImage;
using (var backgroundSource = new BitmapImageSource(ellipseImage.AsBitmap()))
using (var foregroundSource = new BitmapImageSource(image.AsBitmap()))
using (var filterEffect = new FilterEffect(backgroundSource))
{
using (BlendFilter blendFilter = new BlendFilter())
{
blendFilter.ForegroundSource = foregroundSource;
blendFilter.BlendFunction = BlendFunction.Darken;
filterEffect.Filters = new[] { blendFilter };
var OutputBitmap = new WriteableBitmap(image.PixelWidth, image.PixelHeight);
var result = await new WriteableBitmapRenderer(filterEffect, OutputBitmap).RenderAsync();
ImageViewer.Source = result;
}
}