我已经在我的应用中打开图像,并使用以下代码获取图像的像素数据。
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();
}
在这里,我得到了图像所有像素的数组。此数组中的像素总数为((width * height * 4)] >>。在分析了此数组之后,我知道索引号0、1、2和3包含第一个像素的红色,绿色蓝色和alpha值,索引号4、5、6和7包含红色,绿色,蓝色和alpha图像的第二个像素的值,依此类推。
现在,我要将3x3滤镜应用于此图像,如何使用此一维数组呢?如果我有图像的二维数组,我知道该怎么做。
现在,我脑子里有了一个主意。
这是一个好的解决方案吗?如果有更好的解决方案,请帮助我。
我已经在我的应用程序中打开了一个图像,并使用以下代码获取图像的像素数据。使用(IRandomAccessStream fileStreams =等待文件.OpenAsync(Windows.Storage.FileAccessMode ....
如果要在UWP中屏蔽Bitmapimage,则需要对图像的原始像素数据使用软件位图。首先,您需要分离图像和蒙版数据,并将其转换为BGRA格式的字节数组。然后,您需要使用不安全的代码访问该位置以实现此目的。