前田稔(Maeda Minoru)の超初心者のプログラム入門
Microsoft::WRL::ComPtr<ID2D1DeviceContext1> m_d2dContext; Microsoft::WRL::ComPtr<IWICImagingFactory2> m_wicFactory; |
m_d2dContext = m_deviceResources->GetD2DDeviceContext(); m_wicFactory = m_deviceResources->GetWicImagingFactory(); |
Microsoft::WRL::ComPtr<ID2D1Bitmap1> LoadImageFile(PCWSTR uri); Microsoft::WRL::ComPtr<ID2D1DeviceContext1> m_d2dContext; Microsoft::WRL::ComPtr<IWICImagingFactory2> m_wicFactory; Microsoft::WRL::ComPtr<ID2D1Bitmap1> m_bitmapPerspective; |
App1Main::App1Main(const std::shared_ptr<DX::DeviceResources>& deviceResources) : m_deviceResources(deviceResources) { ・・・ m_d2dContext = m_deviceResources->GetD2DDeviceContext(); m_wicFactory = m_deviceResources->GetWicImagingFactory(); m_bitmapPerspective = LoadImageFile(L"ayu.jpg"); } |
bool App1Main::Render() { ・・・ m_d2dContext->BeginDraw(); m_d2dContext->Clear(D2D1::ColorF(D2D1::ColorF::CornflowerBlue)); m_d2dContext->DrawBitmap(m_bitmapPerspective.Get()); HRESULT hr = m_d2dContext->EndDraw(); if (hr != D2DERR_RECREATE_TARGET) { DX::ThrowIfFailed(hr); } return true; } |
// ★LoadImageFile 関数 前田 稔 Microsoft::WRL::ComPtr<ID2D1Bitmap1> App1Main::LoadImageFile(PCWSTR uri) { Microsoft::WRL::ComPtr<ID2D1Bitmap1> bitmapPerspective; Microsoft::WRL::ComPtr<IWICBitmapDecoder> decoder; DX::ThrowIfFailed( m_wicFactory->CreateDecoderFromFilename( uri, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder ) ); Microsoft::WRL::ComPtr<IWICBitmapFrameDecode> frame; DX::ThrowIfFailed( decoder->GetFrame(0, &frame) ); Microsoft::WRL::ComPtr<IWICFormatConverter> converter; DX::ThrowIfFailed( m_wicFactory->CreateFormatConverter(&converter) ); DX::ThrowIfFailed( converter->Initialize( frame.Get(), GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.0f, WICBitmapPaletteTypeCustom ) ); DX::ThrowIfFailed( m_d2dContext->CreateBitmapFromWicBitmap( converter.Get(), nullptr, &bitmapPerspective ) ); return bitmapPerspective; } |