我正在尝试获取 WinRT 应用程序中每个像素的 RGB 值。我可以访问包含以下内容的字节数组PixelData
但我不知道如何使用它,那么如何从字节数组中提取 RGB 信息?
var bd = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
var pd = await bd.GetPixelDataAsync();
var tempBuffer = pd.DetachPixelData();
var PixelMatrix = new byte[bd.PixelWidth, bd.PixelHeight];
// how do I get the RGB value for PixelMatrix[0,0]?
由于您有 RGB 图像,tempBuffer[k + 0]
是红色通道,tempBuffer[k + 1]
是绿色通道,并且tempBuffer[k + 2]
是蓝色通道,即tempBuffer
是一个一维数组。如果您循环遍历所有像素,则伪代码将是:
for i = 0 to height - 1
for j = 0 to width - 1
k = (i * width + j) * 3
r, g, b = tempBuffer[k + 0], tempBuffer[k + 1], tempBuffer[k + 2]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)