Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować się zalogować lub zmienić katalog.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
W tym temacie przedstawiono proces rysowania IWICBitmapSource przy użyciu narzędzia Direct2D.
Aby narysować źródło mapy bitowej przy użyciu Direct2D
Zdekoduj obraz źródłowy i uzyskaj źródło mapy bitowej. W tym przykładzie IWICBitmapDecoder służy do dekodowania obrazu i pobierania pierwszej ramki obrazu.
// Create a decoder IWICBitmapDecoder *pDecoder = NULL; hr = m_pIWICFactory->CreateDecoderFromFilename( szFileName, // Image to be decoded NULL, // Do not prefer a particular vendor GENERIC_READ, // Desired read access to the file WICDecodeMetadataCacheOnDemand, // Cache metadata when needed &pDecoder // Pointer to the decoder ); // Retrieve the first frame of the image from the decoder IWICBitmapFrameDecode *pFrame = NULL; if (SUCCEEDED(hr)) { hr = pDecoder->GetFrame(0, &pFrame); }Aby poznać dodatkowe typy źródeł map bitowych do rysowania, zobacz Omówienie źródeł map bitowych.
Przekonwertuj źródło mapy bitowej na format pikseli 32bppPBGRA.
Zanim Direct2D będzie mogło używać obrazu, należy go przekonwertować na format pikseli 32bppPBGRA. Aby przekonwertować format obrazu, użyj metody CreateFormatConverter, aby utworzyć obiektIWICFormatConverter. Po utworzeniu użyj metody Initialize, aby wykonać konwersję.
// Format convert the frame to 32bppPBGRA if (SUCCEEDED(hr)) { SafeRelease(&m_pConvertedSourceBitmap); hr = m_pIWICFactory->CreateFormatConverter(&m_pConvertedSourceBitmap); } if (SUCCEEDED(hr)) { hr = m_pConvertedSourceBitmap->Initialize( pFrame, // Input bitmap to convert GUID_WICPixelFormat32bppPBGRA, // Destination pixel format WICBitmapDitherTypeNone, // Specified dither pattern NULL, // Specify a particular palette 0.f, // Alpha threshold WICBitmapPaletteTypeCustom // Palette translation type ); }Utwórz obiekt ID2D1RenderTarget na potrzeby renderowania do uchwytu okna.
// Create a D2D render target properties D2D1_RENDER_TARGET_PROPERTIES renderTargetProperties = D2D1::RenderTargetProperties(); // Set the DPI to be the default system DPI to allow direct mapping // between image pixels and desktop pixels in different system DPI settings renderTargetProperties.dpiX = DEFAULT_DPI; renderTargetProperties.dpiY = DEFAULT_DPI; // Create a D2D render target D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); hr = m_pD2DFactory->CreateHwndRenderTarget( renderTargetProperties, D2D1::HwndRenderTargetProperties(hWnd, size), &m_pRT );Aby uzyskać więcej informacji na temat elementów docelowych renderowania, zobacz Elementy docelowe renderowania Direct2D — omówienie.
Utwórz obiekt ID2D1Bitmap przy użyciu metody ID2D1RenderTarget::CreateBitmapFromWicBitmap.
// D2DBitmap may have been released due to device loss. // If so, re-create it from the source bitmap if (m_pConvertedSourceBitmap && !m_pD2DBitmap) { m_pRT->CreateBitmapFromWicBitmap(m_pConvertedSourceBitmap, NULL, &m_pD2DBitmap); }Rysuj ID2D1Bitmap za pomocą metody D2D ID2D1RenderTarget::DrawBitmap.
// Draws an image and scales it to the current window size if (m_pD2DBitmap) { m_pRT->DrawBitmap(m_pD2DBitmap, rectangle); }
Kod został pominięty w tym przykładzie. Aby uzyskać pełny kod, zobacz Podgląd obrazów WIC wykorzystujący przykładowy kod Direct2D.
Zobacz też