我在我的应用程序中打开了一张图片,并使用以下代码获取图像的像素数据。
using (IRandomAccessStream fileStreams = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStreams);
BitmapTransform transform = new BitmapTransform()
{
ScaledWidth = Convert.ToUInt32(bitmapImage.PixelWidth),
ScaledHeight = Convert.ToUInt32(bitmapImage.PixelHeight)
};
PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Straight,
transform,
ExifOrientationMode.IgnoreExifOrientation,
ColorManagementMode.DoNotColorManage
);
byte[] sourcePixels = pixelData.DetachPixelData();
}
这里我有一组图像的所有像素数组。这个数组中的像素总数为(宽度*高度*4)。分析这个数组后,我发现索引号0、1、2和3包含第一个像素的红色、绿色、蓝色和alpha值,索引号4、5、6和7包含图像第二个像素的红色、绿色、蓝色和alpha值,以此类推。
现在我想把我的3x3滤波器应用到这张图片上,但是我该如何使用这个一维数组呢?如果我有图像的二维数组,我知道如何做。
目前,我有一个想法。
- 将红色像素存储在一个2D数组中,绿色在另一个数组中,以此类推。
- 对每个2D数组应用滤波器。
- 再次合并所有这些数组,以重新生成1-D数组并返回结果。