本文整理汇总了C++中IWICImagingFactory::CreateBitmapFromMemory方法的典型用法代码示例。如果您正苦于以下问题:C++ IWICImagingFactory::CreateBitmapFromMemory方法的具体用法?C++ IWICImagingFactory::CreateBitmapFromMemory怎么用?C++ IWICImagingFactory::CreateBitmapFromMemory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWICImagingFactory
的用法示例。
在下文中一共展示了IWICImagingFactory::CreateBitmapFromMemory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnRender
HRESULT Application::OnRender()
{
HRESULT hr = S_OK;
hr = CreateDeviceResources();
if(SUCCEEDED(hr))
{
_pRenderTarget->BeginDraw();
_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));
D2D1_SIZE_F rtSize = _pRenderTarget->GetSize();
// Draw a grid background.
int width = static_cast<int>(rtSize.width);
int height = static_cast<int>(rtSize.height);
for (int x = 0; x < width; x += 10) {
_pRenderTarget->DrawLine(D2D1::Point2F(static_cast<FLOAT>(x), 0.0f), D2D1::Point2F(static_cast<FLOAT>(x), rtSize.height), _pLightSlateGrayBrush, 0.5f);
}
for (int y = 0; y < height; y += 10) {
_pRenderTarget->DrawLine(D2D1::Point2F(0.0f, static_cast<FLOAT>(y)), D2D1::Point2F(rtSize.width, static_cast<FLOAT>(y)), _pLightSlateGrayBrush, 0.5f);
}
// Try to draw bitmap.
if(_buffer != 0) {
// Why? http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/17e9e6bd-aa91-40a3-afc9-3241a24afe00
IWICBitmap *pEmbeddedBitmap;
ID2D1Bitmap *pBitmap;
IWICImagingFactory *pFactory = NULL;
HDC screen = GetDC(0);
float dpiScaleX = GetDeviceCaps(screen, LOGPIXELSX) / 96.0f;
float dpiScaleY = GetDeviceCaps(screen, LOGPIXELSY) / 96.0f;
ReleaseDC(0, screen);
CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*) &pFactory);
HDC memDC = CreateCompatibleDC(screen);
hr = pFactory->CreateBitmapFromMemory(_width, _height, GUID_WICPixelFormat32bppPBGRA, _width * 4, _numBytes, _buffer, &pEmbeddedBitmap);
if(SUCCEEDED(hr)) {
hr = _pRenderTarget->CreateBitmapFromWicBitmap(pEmbeddedBitmap, &pBitmap);
_pRenderTarget->DrawBitmap(pBitmap);
}
}
hr = _pRenderTarget->EndDraw();
}
if(hr == D2DERR_RECREATE_TARGET)
{
hr = S_OK;
DiscardDeviceResources();
}
return hr;
}
示例2: _PerformFlipRotateUsingWIC
//-------------------------------------------------------------------------------------
// Do flip/rotate operation using WIC
//-------------------------------------------------------------------------------------
static HRESULT _PerformFlipRotateUsingWIC( _In_ const Image& srcImage, _In_ DWORD flags,
_In_ const WICPixelFormatGUID& pfGUID, _In_ const Image& destImage )
{
if ( !srcImage.pixels || !destImage.pixels )
return E_POINTER;
assert( srcImage.format == destImage.format );
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmap> source;
HRESULT hr = pWIC->CreateBitmapFromMemory( static_cast<UINT>( srcImage.width ), static_cast<UINT>( srcImage.height ), pfGUID,
static_cast<UINT>( srcImage.rowPitch ), static_cast<UINT>( srcImage.slicePitch ),
srcImage.pixels, &source );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapFlipRotator> FR;
hr = pWIC->CreateBitmapFlipRotator( &FR );
if ( FAILED(hr) )
return hr;
hr = FR->Initialize( source.Get(), static_cast<WICBitmapTransformOptions>( flags ) );
if ( FAILED(hr) )
return hr;
WICPixelFormatGUID pfFR;
hr = FR->GetPixelFormat( &pfFR );
if ( FAILED(hr) )
return hr;
if ( memcmp( &pfFR, &pfGUID, sizeof(GUID) ) != 0 )
{
// Flip/rotate should return the same format as the source...
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
}
UINT nwidth, nheight;
hr = FR->GetSize( &nwidth, &nheight );
if ( FAILED(hr) )
return hr;
if ( destImage.width != nwidth || destImage.height != nheight )
return E_FAIL;
hr = FR->CopyPixels( 0, static_cast<UINT>( destImage.rowPitch ), static_cast<UINT>( destImage.slicePitch ), destImage.pixels );
if ( FAILED(hr) )
return hr;
return S_OK;
}