C++ 读写WriteableBitmap数据方法

来源:互联网 发布:减肥过快皮肤松弛 知乎 编辑:程序博客网 时间:2024/05/21 19:44

项目,需要用C#做APP,进行图像读取,显示,用C++ WinRT Component 做算法,进行图像处理 。原来直接在C#中把图像原始数据读取出来,传递给WinRT DLL.导致接口一直很不友好。

今天重写接口,传WriteableBitmap对象,在C++中读取raw data,进行处理 。

byte* BufferFromWriteableBitmap(WriteableBitmap^ bitmap){IUnknown* pUnknown = reinterpret_cast<IUnknown*>(bitmap->PixelBuffer);IBufferByteAccess* pBufferByteAccess = nullptr;HRESULT hr = pUnknown->QueryInterface(IID_PPV_ARGS(&pBufferByteAccess));pUnknown->Release();byte *pPixels = nullptr;hr = pBufferByteAccess->Buffer(&pPixels);return pPixels;}


得到的指针就是图像数据的位置,可以直接进行修改。

WriteableBitmap^ result = ref new WriteableBitmap(lWidth,lHeight);byte *pPixels = BufferFromWriteableBitmap(result);//YUYV_to_BGRA8888(DstImg.ppu8Plane[0],pPixels,lWidth,lHeight,DstImg.pi32Pitch[0],lWidth*4);


还需要头文件

 

 

#include "Robuffer.h"using namespace Windows::Storage::Streams;


 

 

原创粉丝点击