• 大小: 407KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-07
  • 语言: C/C++
  • 标签: D2D  

资源简介

D2D显示图片(MFC)

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “baseFactory.h“

#include “FX_WICBitmapDecoder.h“

baseFactory::baseFactory(void)
{
}

bool baseFactory::Initialize(HWND hwnd)
{
HRESULT hr = S_OK;
m_hwnd = hwnd;
m_pRenderTarget = nullptr;
m_pBitmap = nullptr;
m_pBitmap1 = nullptr;
CreateDeviceIndependentResources();
hr = CreateDeviceResources();
return true;
}

baseFactory::~baseFactory(void)
{
}

HRESULT baseFactory::CreateDeviceIndependentResources()
{
HRESULT hr = S_OK;

// Create a Direct2D factory.
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED &m_pDirect2dFactory);

IDWriteFactory* pDWriteFactory_ = NULL;
hr = DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED
__uuidof(IDWriteFactory)
reinterpret_cast(&pDWriteFactory_)
);

m_wicFactory = nullptr;
if (!SUCCEEDED(CoInitialize(NULL)))
{
MessageBox(NULLL“Error“NULLMB_OK);
return -1;
}
hr = CoCreateInstance(CLSID_WICImagingFactory
nullptr//
//CLSCTX_INPROC//
CLSCTX_INPROC_SERVER
//IID_IWICImagingFactory
//(LPVOID*)&m_wicFactory

IID_PPV_ARGS(&m_wicFactory)
);
IWICImagingFactory *pFactory = NULL;
IWICBitmapDecoder *pDecoder = NULL; 

HRESULT hr1 = CoCreateInstance(
CLSID_WICImagingFactory
NULL
CLSCTX_INPROC_SERVER
IID_IWICImagingFactory
(LPVOID*)&pFactory
);
FX_WICBitmapDecoder pBitmapDecoder;// = new FX_WICBitmapDecoder();
pBitmapDecoder.Initialize(m_wicFactory);
IWICBitmapDecoder* wicBitmapDecoder;
//从文件中创建解码器文件必须存在
pBitmapDecoder.CreateDecoderFromFilename(L“努力.jpg“
&wicBitmapDecoder);
pBitmapDecoder.CreateFormatConverter(wicBitmapDecoder&m_pWicFormatConverter);
return hr;
}

HRESULT baseFactory::CreateDeviceResources()
{
HRESULT hr = S_OK;

if (!m_pRenderTarget)
{
RECT rc;
GetClientRect(m_hwnd &rc);

D2D1_SIZE_U size = D2D1::SizeU(
rc.right - rc.left
rc.bottom - rc.top
);

// Create a Direct2D render target.
hr = m_pDirect2dFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties()
D2D1::HwndRenderTargetProperties(m_hwnd size)
&m_pRenderTarget
);
//创建位图
m_pRenderTarget->CreateBitmapFromWicBitmap(m_pWicFormatConverter
&m_pBitmap);
}
return hr;
}

void baseFactory::DiscardDeviceResources()
{
SafeRelease(&m_pRenderTarget);
SafeRelease(&m_pLightSlateGrayBrush);
SafeRelease(&m_pCornflowerBlueBrush);
}

HRESULT baseFactory::OnRender()
{

HRESULT hr = S_OK;

m_pRenderTarget->BeginDraw();

m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());

m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

D2D1_SIZE_F rtSize = m_pRenderTarget->GetSize();

// Draw a grid background.
int width = static_cast(rtSize.width);
int height = static_cast(rtSize.height);

D2D1_SIZE_U bmpSize = m_pBitmap->GetPixelSize();

m_pRenderTarget->DrawBitmap(m_pBitmapD2D1::RectF(0 0 bmpSize.width bmpSize.height));

hr = m_pRend

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-05-19 18:37  D2D_Demo\
     目录           0  2013-05-19 19:17  D2D_Demo\Test\
     目录           0  2013-05-19 19:17  D2D_Demo\Test\Test\
     文件         879  2013-05-19 18:37  D2D_Demo\Test\Test.sln
     文件       19456  2013-05-19 19:16  D2D_Demo\Test\Test.suo
     文件        3389  2013-05-19 19:15  D2D_Demo\Test\Test\baseFactory.cpp
     文件        3112  2013-05-19 19:05  D2D_Demo\Test\Test\baseFactory.h
     文件        2597  2013-05-19 18:45  D2D_Demo\Test\Test\FX_WICBitmapDecoder.cpp
     文件         640  2013-01-28 14:59  D2D_Demo\Test\Test\FX_WICBitmapDecoder.h
     文件        4599  2013-05-19 18:37  D2D_Demo\Test\Test\ReadMe.txt
     目录           0  2013-05-19 18:37  D2D_Demo\Test\Test\res\
     文件         529  2013-05-19 18:37  D2D_Demo\Test\Test\Resource.h
     文件       67777  2009-08-31 02:31  D2D_Demo\Test\Test\res\Test.ico
     文件         792  2013-05-19 18:37  D2D_Demo\Test\Test\res\Test.rc2
     文件         316  2013-05-19 18:47  D2D_Demo\Test\Test\stdafx.cpp
     文件        1807  2013-05-19 18:37  D2D_Demo\Test\Test\stdafx.h
     文件         314  2013-05-19 18:37  D2D_Demo\Test\Test\targetver.h
     文件      105472  2013-05-19 18:41  D2D_Demo\Test\Test\Test.aps
     文件        2443  2013-05-19 18:37  D2D_Demo\Test\Test\Test.cpp
     文件         493  2013-05-19 18:37  D2D_Demo\Test\Test\Test.h
     文件       10752  2013-05-19 18:41  D2D_Demo\Test\Test\Test.rc
     文件        6312  2013-05-19 19:12  D2D_Demo\Test\Test\Test.vcxproj
     文件        2409  2013-05-19 19:10  D2D_Demo\Test\Test\Test.vcxproj.filters
     文件         143  2013-05-19 18:37  D2D_Demo\Test\Test\Test.vcxproj.user
     文件        4076  2013-05-19 19:16  D2D_Demo\Test\Test\TestDlg.cpp
     文件         758  2013-05-19 19:12  D2D_Demo\Test\Test\TestDlg.h
     文件      281576  2012-12-14 23:02  D2D_Demo\Test\Test\努力.jpg

评论

共有 条评论

相关资源