2017-04-26 78 views
0

我試圖將圖像轉換爲位圖以便使用AForge濾鏡。在MSN網站上,我看到Bitmap有一個圖像構造器,但是當我嘗試它時不起作用。這是我的代碼有:UWP圖像到位圖轉換

     Bitmap bitmap = new Bitmap(image1); 
+0

什麼圖像1的數據類型?也是什麼意思,「它不工作」 – user2366842

+0

image1是一個Windows.UI.Xaml.Controls.Image,並按照上面的做法告訴我,位圖不包含構造函數,這與他們所說的構造函數相矛盾在他們的網站上。 –

+0

你嘗試過直接投射嗎? '位圖位=此搜索作爲Bitmap' – GibralterTop

回答

2

不能System.Drawing.BitmapWindows.UI.Xaml.Controls.Image之間的直接轉換。

將AForge視爲使用Bitmap類,而UWP使用WritableBitmap作爲其圖像。你需要找到一種方法來在兩者之間進行轉換。

看看這個Aforge.Net libraryUsage部分,它提供了做事情的一種方法(引):

// 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; 
+0

我可以看到Aforge.Net源代碼嗎? – lindexi

+0

這裏有一個[link](https://code.google.com/archive/p/aforge/source/default/source)從他們的網站 – Tee

+0

Thx的官方Aforge.Net源代碼,但比較說'aWriteableBitmapObject =(WriteableBitmap)位圖;'位圖不能轉換爲WriteableBitmap – lindexi