![](/img/trans.png)
[英]Classification with Accord.net library throw IndexOutOfRangeException
[英]Converting BitmapImage to Bitmap (Windows Phone 8.1 using Accord.net Portable Library)
我正在使用Accord.net Portable Library在Windows Phone 8.1中创建一个简单的图像处理应用程序。 我的主要目标是使用灰度从我的图片库(在 .jpeg 中)过滤彩色图像。 Accord.net Portable 库允许在System.Drawing下的 Windows Phone 中使用Bitmap ,以便我可以执行图像处理方法。
问题是我正在使用Open File Picker ,它在从图片库中获取图像时使用BitmapImage 。 这是我的代码:
public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
{
if (args.Files != null)
{
StorageFile file = args.Files[0];
bitmapImage = new BitmapImage();
using (var stream = await file.OpenReadAsync())
{
await bitmapImage.SetSourceAsync(stream);
}
}
img_Original.Source = bitmapImage;
}
https://github.com/cureos/accord/blob/portable/Sources/Accord.Imaging/AForge/Filters/Color%20Filters/Grayscale.cs 中提供的示例 Grayscale.cs 类告诉我可以简单地使用以下代码以便我可以执行灰度过滤器:
Grayscale filter = new Grayscale( 0.2125, 0.7154, 0.0721 );
Bitmap grayImage = filter.Apply( image );
而image应该是一种Bitmap 。 如您所见,我不能使用bitmapImage变量,因为它是一种BitmapImage 。 另一个问题是,位图不包含任何构造函数(与在 WinForms 中不同)。 所以我真的没有选择如何将灰度过滤器应用于现有图像。 另一个可能有帮助的信息是,当我悬停到 filter.Apply 构造函数时,它包含除Bitmap之外的数据类型。 BitmapData和UnmanagedImage 。 但是我不知道如何使用这些数据类型。
我可以利用的任何解决方法,将不胜感激。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.