2016-09-15 53 views
0

我什麼都試過,但WriteableBitmap的類只是沒有.CopyPixels()喜歡它的方法在droumentation說:https://msdn.microsoft.com/de-de/library/system.windows.media.imaging.writeablebitmap_methods(v=vs.110).aspx如何從WriteableBitmap獲取像素的顏色?

對微軟的Visual Studio 2015年強調紅舉例:

writeableBitmap.CopyPixels(new Int32Rect(0, 0, 20, 10),pixels, 20 * 4, 0); 
+0

它在我的環境中正常工作。您是否包含對PresentationCore的引用? DLL? – Trifon

+0

現在......是的,還有第二個原因,它沒有奏效。我使用「使用Windows.UI.Xaml.Media.Imaging;」而不是「使用System.Windows.Media.Imaging;」。謝謝:) – Fabian

回答

1

根據你的描述,你想要的是WriteableBitmap classUWP。但是,您引用的文檔是中的WriteableBitmap Class .NET Framework,它在傳統桌面應用程序中使用。有關配套文件,請參閱WriteableBitmap class

以及在UWP的的WriteableBitmap class,我們可以使用WriteableBitmap.PixelBuffer property從像WriteableBitmap拿到像素:

byte[] pixels = writeableBitmap.PixelBuffer.ToArray(); 

欲瞭解更多信息,請參閱XAML images sample。儘管這是一款Windows 8.1商店應用程序,但它在UWP應用程序中是一樣的。

+0

我試過這個解決方案,但是我得到一個錯誤:'值不能爲空。\ r \ n參數名稱:source'。也許你有這個問題的想法http://stackoverflow.com/questions/39817619/converting-a-writeablebitmap-image-toarray-in-uwp – JTIM