使用下面的函數,我遇到了試圖訪問WriteableBitmap.PixelBuffer屬性的問題。我得到的消息是:'using'聲明被忽略
'WriteableBitmap' does not contain a definition for 'PixelBuffer' and no extension method 'PixelBuffer' accepting a first argument of type 'WriteableBitmap' could be found (are you missing a using directive or an assembly reference?)
我看過其他地方,我需要包括
using System.Runtime.InteropServices.WindowsRuntime;
但是當我使用這包括,沒有在我的代碼更改。通過我的解決方案的參考看,我沒有看到任何像System.Runtime.InteropServices。我很沮喪,因爲這似乎是其他人嘗試訪問WriteableBitmap的PixelBuffer的解決方案。
private WriteableBitmap ChangeBrightness(WriteableBitmap source, byte change_value)
{
WriteableBitmap dest = new WriteableBitmap(source);
byte[] color = new byte[4];
using (Stream s = source.PixelBuffer.AsStream())
{
using (Stream d = dest.PixelBuffer.AsStream())
{
// read the pixel color
while (s.Read(color, 0, 4) > 0)
{
// color[0] = b
// color[1] = g
// color[2] = r
// color[3] = a
// do the adding algo per byte (skip the alpha)
for (int i = 0; i < 4; i++)
{
if ((int)color[i] + change_value > 255) color[i] = 255; else color[i] = (byte)(color[i] + change_value);
}
// write the new pixel color
d.Write(color, 0, 4);
}
}
}
// return the new bitmap
return dest;
}
你的代碼的哪部分不工作? 'WriteableBitmap'不被識別或者是什麼? – MrZander
'PixelBuffer'似乎是['Windows.UI.Xaml.Media.Imaging.WriteableBitmap']的成員(https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml。 media.imaging.writeablebitmap#Windows_UI_Xaml_Media_Imaging_WriteableBitmap_PixelBuffer),你用錯了嗎? – DavidG
http://stackoverflow.com/questions/20478467/stream-stream-writeablebitmap-pixelbuffer-asstream-missing這似乎是相關的,特別是關於程序集/命名空間的問題的評論 – MrZander