我試圖將圖像轉換爲位圖以便使用AForge濾鏡。在MSN網站上,我看到Bitmap有一個圖像構造器,但是當我嘗試它時不起作用。這是我的代碼有:UWP圖像到位圖轉換
Bitmap bitmap = new Bitmap(image1);
我試圖將圖像轉換爲位圖以便使用AForge濾鏡。在MSN網站上,我看到Bitmap有一個圖像構造器,但是當我嘗試它時不起作用。這是我的代碼有:UWP圖像到位圖轉換
Bitmap bitmap = new Bitmap(image1);
不能System.Drawing.Bitmap
和Windows.UI.Xaml.Controls.Image
之間的直接轉換。
將AForge視爲使用Bitmap
類,而UWP使用WritableBitmap作爲其圖像。你需要找到一種方法來在兩者之間進行轉換。
看看這個Aforge.Net library的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;
什麼圖像1的數據類型?也是什麼意思,「它不工作」 – user2366842
image1是一個Windows.UI.Xaml.Controls.Image,並按照上面的做法告訴我,位圖不包含構造函數,這與他們所說的構造函數相矛盾在他們的網站上。 –
你嘗試過直接投射嗎? '位圖位=此搜索作爲Bitmap' – GibralterTop