【发布时间】:2018-11-13 03:31:59
【问题描述】:
我有一个可能很愚蠢的问题,但我不知道如何自己解决。
我从 SoftwareBitmap 的像素数据中获得了一个 byte* 指针,然后我编辑了一些像素数据……现在我不知道如何使用那个 byte* 指针。
如何将其转换为 IBuffer,例如,以便使用它来创建新的 SoftwareBitmap? 有没有更简单的方法来创建新的位图?
这是代码,顺便说一句,甚至认为它不应该有任何帮助:
-
DLL 导入
[ComImport] [Guid("5b0d3235-4dba-4d44-865e-8f1d0e4fd04d")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] unsafe interface IMemoryBufferByteAccess { void GetBuffer(out byte* buffer, out uint capacity); } -
主要功能
private unsafe SoftwareBitmap PixelateImage(SoftwareBitmap bitmap, Boolean AlphaEnabled) { using (var buffer = bitmap.LockBuffer(BitmapBufferAccessMode.Read)) { using (var reference = buffer.CreateReference()) { ((IMemoryBufferByteAccess)reference).GetBuffer(out byte* data, out uint capacity); // Doing things with data[int index] bytes… SoftwareBitmap bmp = new SoftwareBitmap(bitmap.BitmapPixelFormat, bitmap.PixelWidth, bitmap.PixelHeight, bitmap.BitmapAlphaMode); // How to use byte* data else? // bmp.CopyFromBuffer(IBuffer) <=== How to get an IBuffer from byte*? return bmp; } } }
谢谢大家。
【问题讨论】:
标签: c# arrays image pointers uwp