你可以通过BitmapDecoder和PixelDataProvider得到文件流pxiel数据:
Windows.Storage.Streams.IRandomAccessStream random = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/StoreLogo.png")).OpenReadAsync();
Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(random);
Windows.Graphics.Imaging.PixelDataProvider pixelData = await decoder.GetPixelDataAsync();
byte[] buffer = pixelData.DetachPixelData();
然后,你可以从字节数组通过不安全的代码
unsafe
{
fixed (byte* p = buffer)
{
IntPtr ptr = (IntPtr)p;
// do you stuff here
}
}
得到的IntPtr如果编译不安全的代码,你需要在项目的构建属性中启用允许不安全代码选项。
一个'IntPtr'什么? 'BitmapImage'实例?像素数据?还有别的吗? – IInspectable
我想获得一个IntPtr从指针地址。 (图像在存储器中定位的像素地址)。因此,我可以逐像素地使用它 –