bool CDirectWriteBrush::Create(CDirectWriteRenderer &Renderer, BYTE Red, BYTE Green, BYTE Blue, BYTE Alpha) { Destroy(); ID2D1RenderTarget *pRenderTarget = Renderer.GetRenderTarget(); if (pRenderTarget == nullptr) return false; ID2D1SolidColorBrush *pBrush; HRESULT hr = pRenderTarget->CreateSolidColorBrush( D2DColorF(Red, Green, Blue, Alpha), &pBrush); if (SUCCEEDED(hr)) m_pBrush = pBrush; pRenderTarget->Release(); return true; }
void ImageWindow::AssociateSurface( void* surface ) { if (pD2DFactory) { // Assume an IUnknown IUnknown* unknown = (IUnknown*)surface; IDXGISurface *pDxgiSurface = NULL; HRESULT hr = unknown->QueryInterface(&pDxgiSurface); if( hr == S_OK ) { D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties( D2D1_RENDER_TARGET_TYPE_DEFAULT, D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED), 96, 96 ); pRT = NULL; ID2D1RenderTarget* tmpTarget; hr = pD2DFactory->CreateDxgiSurfaceRenderTarget( pDxgiSurface, &props, &tmpTarget ); if( hr == S_OK ) { DXGI_SURFACE_DESC desc = {0}; pDxgiSurface->GetDesc( &desc ); int width = desc.Width; int height = desc.Height; D2D1_SIZE_U size = D2D1::SizeU( width, height ); D2D1_PIXEL_FORMAT pixelFormat = D2D1::PixelFormat( DXGI_FORMAT_A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED ); D2D1_PIXEL_FORMAT colorPixelFormat = D2D1::PixelFormat( DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED ); D2D1_BITMAP_PROPERTIES bitmapProps; bitmapProps.dpiX = 96; bitmapProps.dpiY = 96; bitmapProps.pixelFormat = pixelFormat; D2D1_BITMAP_PROPERTIES colorBitmapProps; colorBitmapProps.dpiX = 96; colorBitmapProps.dpiY = 96; colorBitmapProps.pixelFormat = colorPixelFormat; HRESULT result = tmpTarget->CreateBitmap( size, bitmapProps, &greyBitmap ); if( result != S_OK ) { tmpTarget->Release(); tmpTarget = NULL; } if (tmpTarget) { result = tmpTarget->CreateBitmap(size, colorBitmapProps, &colorBitmap); if (result != S_OK) { tmpTarget->Release(); tmpTarget = NULL; } } pRT = tmpTarget; } } } }