Skip to content

Commit

Permalink
feat:实现内嵌图片二进制
Browse files Browse the repository at this point in the history
  • Loading branch information
GengGode committed Feb 7, 2023
1 parent 5c69439 commit 4b49842
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions cvAutoTrack/src/resources/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,74 @@
#include "Resources.h"
#include "resource.h"
#include <wincodec.h>
#include "resources/image_binary/Resource.ImageBinary.h"
namespace TianLi::Resource::Utils
{
//TianLi::Resource::ImageBinary::bin_paimon_png

/// <summary>
/// .png file binary data to cv::Mat
/// </summary>
/// <param name="image_binary"></param>
/// <param name="mat"></param>
void binary_to_mat(const unsigned char* image_binary, cv::Mat& mat)
{
auto image_array = cv::Mat(1, sizeof(image_binary), CV_8UC1, (void*)image_binary);
mat = cv::imdecode(image_array, cv::IMREAD_UNCHANGED);
}
/// <summary>
/// .png file binary data to cv::Mat
/// </summary>
/// <param name="image_binary"></param>
/// <param name="mat"></param>
void binary_to_mat_com(const unsigned char* image_binary, cv::Mat& mat)
{
IWICImagingFactory* pFactory = NULL;
IWICBitmapDecoder* pDecoder = NULL;
IWICBitmapFrameDecode* pFrame = NULL;
IWICFormatConverter* pConverter = NULL;
IWICStream* pStream = NULL;
HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFactory));
}
if (SUCCEEDED(hr))
{
hr = pFactory->CreateStream(&pStream);
}
if (SUCCEEDED(hr))
{
hr = pStream->InitializeFromMemory((BYTE*)image_binary, sizeof(image_binary));
}
if (SUCCEEDED(hr))
{
hr = pFactory->CreateDecoderFromStream(pStream, NULL, WICDecodeMetadataCacheOnDemand, &pDecoder);
}
if (SUCCEEDED(hr))
{
hr = pDecoder->GetFrame(0, &pFrame);
}
if (SUCCEEDED(hr))
{
hr = pFactory->CreateFormatConverter(&pConverter);
}
if (SUCCEEDED(hr))
{
hr = pConverter->Initialize(pFrame, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, NULL, 0.f, WICBitmapPaletteTypeCustom);
}
if (SUCCEEDED(hr))
{
UINT width, height;
hr = pConverter->GetSize(&width, &height);
if (SUCCEEDED(hr))
{
mat.create(height, width, CV_8UC4);
hr = pConverter->CopyPixels(NULL, width * 4, mat.total() * mat.elemSize(), mat.data);
}
}
}

void LoadBitmap_ID2Mat(int IDB, cv::Mat& mat)
{
auto H_Handle = LoadBitmap(GetModuleHandleW(L"CVAUTOTRACK.dll"), MAKEINTRESOURCE(IDB));
Expand Down

0 comments on commit 4b49842

Please sign in to comment.