• 大小: 23KB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: 其他
  • 标签: Kinect  C++  笑面男  

资源简介

《Kinect for Windows SDK v2.0 开发笔记 (五)骨骼帧与笑面男》附带资源

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “included.h“
#include 


static const float c_JointThickness = 3.0f;
static const float c_TrackedBoneThickness = 6.0f;
static const float c_InferredBoneThickness = 1.0f;
static const float c_HandSize = 30.0f;

// ImageRender类构造函数
ImageRenderer::ImageRenderer(){
// 创建资源
m_hrInit = CreateDeviceIndependentResources();
    m_timer.Start();
}


// 创建设备无关资源
HRESULT ImageRenderer::CreateDeviceIndependentResources(){
HRESULT hr = S_OK;

// 创建 Direct2D 工厂.
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED &m_pD2DFactory);

if (SUCCEEDED(hr))
{
// 创建 WIC 工厂.
hr = CoCreateInstance(
CLSID_WICImagingFactory
NULL
CLSCTX_INPROC_SERVER
IID_IWICImagingFactory
reinterpret_cast(&m_pWICFactory)
);
}

if (SUCCEEDED(hr))
{
// 创建 DirectWrite 工厂.
hr = DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED
__uuidof(m_pDWriteFactory)
reinterpret_cast(&m_pDWriteFactory)
);
}

if (SUCCEEDED(hr))
{
// 创建正文文本格式.
hr = m_pDWriteFactory->CreateTextFormat(
L“Microsoft YaHei“
nullptr
DWRITE_FONT_WEIGHT_NORMAL
DWRITE_FONT_style_NORMAL
DWRITE_FONT_STRETCH_NORMAL
60.f
L““ //locale
&m_pTextFormatMain
);
}

return hr;
}

// 从文件读取位图
HRESULT ImageRenderer::LoadBitmapFromFile(
ID2D1RenderTarget *pRenderTarget
IWICImagingFactory *pIWICFactory
PCWSTR uri
UINT destinationWidth
UINT destinationHeight
ID2D1Bitmap **ppBitmap

{
IWICBitmapDecoder *pDecoder = NULL;
IWICBitmapframeDecode *pSource = NULL;
IWICStream *pStream = NULL;
IWICFormatConverter *pConverter = NULL;
IWICBitmapScaler *pScaler = NULL;

HRESULT hr = pIWICFactory->CreateDecoderFromFilename(
uri
NULL
GENERIC_READ
WICDecodemetadataCacheonload
&pDecoder
);

if (SUCCEEDED(hr))
{
hr = pDecoder->Getframe(0 &pSource);
}
if (SUCCEEDED(hr))
{
hr = pIWICFactory->CreateFormatConverter(&pConverter);
}


if (SUCCEEDED(hr))
{
if (destinationWidth != 0 || destinationHeight != 0)
{
UINT originalWidth originalHeight;
hr = pSource->GetSize(&originalWidth &originalHeight);
if (SUCCEEDED(hr))
{
if (destinationWidth == 0)
{
FLOAT scalar = static_cast(destinationHeight) / static_cast(originalHeight);
destinationWidth = static_cast(scalar * static_cast(originalWidth));
}
else if (destinationHeight == 0)
{
FLOAT scalar = static_cast(destinationWidth) / static_cast(originalWidth);
destinationHeight = static_cast(scalar * static_cast(originalHeight));
}

hr = pIWICFactory->CreateBitmapScaler(&pScaler);
if (SUCCEEDED(hr))
{
hr = pScaler->Initialize(
pSource
destinationWidth
destinationHeight
WICBitmapInterpolationModeCubic
);
}
if (SUCCEEDED(hr))
{

评论

共有 条评论