简体   繁体   English

UWP图像到位图的转换

[英]UWP Image to Bitmap Conversion

I'm trying to convert an image to a bitmap in order to use AForge filters. 我正在尝试将图像转换为位图,以便使用AForge滤镜。 On MSN website i saw that Bitmap has an image contructor but when i try it it doesn't work. 在MSN网站上,我看到Bitmap有图像构造器,但是当我尝试使用它时,它是行不通的。 This is the code i have : 这是我的代码:

                     Bitmap bitmap = new Bitmap(image1);

You can't convert directly between System.Drawing.Bitmap and Windows.UI.Xaml.Controls.Image . 您不能在System.Drawing.BitmapWindows.UI.Xaml.Controls.Image之间直接转换。

Think of AForge as using the Bitmap class, while UWP uses the WritableBitmap for its images. 将AForge视为使用Bitmap类,而UWP将WritableBitmap用于其图像。 You'll need to find a way to convert between the two. 您需要找到一种在两者之间进行转换的方法。

Take a look at the Usage section of this Aforge.Net library , which provides one way of doing things (Quoted): 看一下这个Aforge.Net库Usage部分,它提供了一种处理方式(已引用):

// Use explicit operator to convert from WriteableBitmap to Bitmap
Bitmap bitmap = (Bitmap)aWriteableBitmapObject;

// Apply one or more filter functions on the Bitmap object
var filter1 = AForge.Imaging.Filters.Grayscale.CommonAlgorithms.RMY;
bitmap = filter1.Apply(bitmap);
var filter2 = new AForge.Imaging.Filters.CannyEdgeDetector();
filter2.ApplyInPlace(bitmap);

// Use explicit operator to convert back from Bitmap to WriteableBitmap
aWriteableBitmapObject = (WriteableBitmap)bitmap;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM