本文整理汇总了C++中IWICImagingFactory::CreateBitmapScaler方法的典型用法代码示例。如果您正苦于以下问题:C++ IWICImagingFactory::CreateBitmapScaler方法的具体用法?C++ IWICImagingFactory::CreateBitmapScaler怎么用?C++ IWICImagingFactory::CreateBitmapScaler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWICImagingFactory
的用法示例。
在下文中一共展示了IWICImagingFactory::CreateBitmapScaler方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateTextureFromWIC
//.........这里部分代码省略.........
{
// Fallback to RGBA 32-bit format which is supported by all devices
memcpy( &convertGUID, &GUID_WICPixelFormat32bppRGBA, sizeof(WICPixelFormatGUID) );
format = DXGI_FORMAT_R8G8B8A8_UNORM;
bpp = 32;
}
// Allocate temporary memory for image
size_t rowPitch = ( twidth * bpp + 7 ) / 8;
size_t imageSize = rowPitch * theight;
std::unique_ptr<uint8_t[]> temp( new (std::nothrow) uint8_t[ imageSize ] );
if (!temp)
return E_OUTOFMEMORY;
// Load image data
if ( memcmp( &convertGUID, &pixelFormat, sizeof(GUID) ) == 0
&& twidth == width
&& theight == height )
{
// No format conversion or resize needed
hr = frame->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );
if ( FAILED(hr) )
return hr;
}
else if ( twidth != width || theight != height )
{
// Resize
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ComPtr<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() );
if ( FAILED(hr) )
return hr;
hr = scaler->Initialize( frame, twidth, theight, WICBitmapInterpolationModeFant );
if ( FAILED(hr) )
return hr;
WICPixelFormatGUID pfScaler;
hr = scaler->GetPixelFormat( &pfScaler );
if ( FAILED(hr) )
return hr;
if ( memcmp( &convertGUID, &pfScaler, sizeof(GUID) ) == 0 )
{
// No format conversion needed
hr = scaler->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );
if ( FAILED(hr) )
return hr;
}
else
{
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
return hr;
BOOL canConvert = FALSE;
hr = FC->CanConvert( pfScaler, convertGUID, &canConvert );
if ( FAILED(hr) || !canConvert )
{
return E_UNEXPECTED;
}
示例2: CreateTextureFromWIC
//.........这里部分代码省略.........
hr = d3dDevice->CheckFormatSupport( format, &support );
if ( FAILED(hr) || !(support & D3D11_FORMAT_SUPPORT_TEXTURE2D) )
{
// Fallback to RGBA 32-bit format which is supported by all devices
memcpy( &convertGUID, &GUID_WICPixelFormat32bppRGBA, sizeof(WICPixelFormatGUID) );
format = DXGI_FORMAT_R8G8B8A8_UNORM;
bpp = 32;
}
// Allocate temporary memory for image
size_t rowPitch = ( twidth * bpp + 7 ) / 8;
size_t imageSize = rowPitch * theight;
std::unique_ptr<uint8_t[]> temp( new uint8_t[ imageSize ] );
// Load image data
if ( memcmp( &convertGUID, &pixelFormat, sizeof(GUID) ) == 0
&& twidth == width
&& theight == height )
{
// No format conversion or resize needed
hr = frame->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );
if ( FAILED(hr) )
return hr;
}
else if ( twidth != width || theight != height )
{
// Resize
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( &scaler );
if ( FAILED(hr) )
return hr;
hr = scaler->Initialize( frame, twidth, theight, WICBitmapInterpolationModeFant );
if ( FAILED(hr) )
return hr;
WICPixelFormatGUID pfScaler;
hr = scaler->GetPixelFormat( &pfScaler );
if ( FAILED(hr) )
return hr;
if ( memcmp( &convertGUID, &pfScaler, sizeof(GUID) ) == 0 )
{
// No format conversion needed
hr = scaler->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );
if ( FAILED(hr) )
return hr;
}
else
{
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
if ( FAILED(hr) )
return hr;
hr = FC->Initialize( scaler.Get(), convertGUID, WICBitmapDitherTypeErrorDiffusion, 0, 0, WICBitmapPaletteTypeCustom );
if ( FAILED(hr) )
return hr;
hr = FC->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );
if ( FAILED(hr) )
示例3: loadAsShaderResource
//.........这里部分代码省略.........
UINT support = 0;
res = dxDev->CheckFormatSupport( format, &support );
if ( FAILED(res) || !(support & D3D11_FORMAT_SUPPORT_TEXTURE2D) )
{
// Fallback to RGBA 32-bit format which is supported by all devices
memcpy( &convertGUID, &GUID_WICPixelFormat32bppRGBA, sizeof(WICPixelFormatGUID) );
format = DXGI_FORMAT_R8G8B8A8_UNORM;
bpp = 32;
}
// Allocate temporary memory for image
size_t rowPitch = ( tWidth * bpp + 7 ) / 8;
size_t imageSize = rowPitch * tHeight;
std::unique_ptr<uint8_t[]> temp( new uint8_t[ imageSize ] );
// Load image data
if ( memcmp( &convertGUID, &pixelFormat, sizeof(GUID) ) == 0
&& tWidth == width
&& tHeight == height )
{
// No format conversion or resize needed
res = frame->CopyPixels( 0, (UINT)rowPitch, (UINT)imageSize, temp.get() );
if ( FAILED(res) )
return res;
} else if ( tWidth != width || tHeight != height )
{
// Resize
IWICImagingFactory* pWIC = getWIC();
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmapScaler> scaler;
res = pWIC->CreateBitmapScaler( &scaler );
if ( FAILED(res) )
return res;
res = scaler->Initialize( frame.get(), tWidth, tHeight, WICBitmapInterpolationModeFant );
if ( FAILED(res) )
return res;
WICPixelFormatGUID pfScaler;
res = scaler->GetPixelFormat( &pfScaler );
if ( FAILED(res) )
return res;
if ( memcmp( &convertGUID, &pfScaler, sizeof(GUID) ) == 0 )
{
// No format conversion needed
res = scaler->CopyPixels( 0, (UINT)rowPitch, (UINT)imageSize, temp.get() );
if ( FAILED(res) )
return res;
} else
{
ScopedObject<IWICFormatConverter> FC;
res = pWIC->CreateFormatConverter( &FC );
if ( FAILED(res) )
return res;
res = FC->Initialize( scaler.get(), convertGUID, WICBitmapDitherTypeErrorDiffusion, 0, 0, WICBitmapPaletteTypeCustom );
if ( FAILED(res) )
return res;
res = FC->CopyPixels( 0, (UINT)rowPitch, (UINT)imageSize, temp.get() );
if ( FAILED(res) )
return res;
示例4: LoadResourceImage
/// <summary>
/// Load an image from a resource into a buffer
/// </summary>
/// <param name="resourceName">name of image resource to load</param>
/// <param name="resourceType">type of resource to load</param>
/// <param name="nOutputWidth">width (in pixels) of scaled output bitmap</param>
/// <param name="nOutputHeight">height (in pixels) of scaled output bitmap</param>
/// <param name="pOutputBuffer">buffer that will hold the loaded image</param>
/// <returns>S_OK on success, otherwise failure code</returns>
HRESULT CCoordinateMappingBasics::LoadResourceImage(PCWSTR resourceName, PCWSTR resourceType, UINT nOutputWidth, UINT nOutputHeight, RGBQUAD* pOutputBuffer)
{
IWICImagingFactory* pIWICFactory = NULL;
IWICBitmapDecoder* pDecoder = NULL;
IWICBitmapFrameDecode* pSource = NULL;
IWICStream* pStream = NULL;
IWICFormatConverter* pConverter = NULL;
IWICBitmapScaler* pScaler = NULL;
HRSRC imageResHandle = NULL;
HGLOBAL imageResDataHandle = NULL;
void *pImageFile = NULL;
DWORD imageFileSize = 0;
HRESULT hrCoInit = CoInitialize(NULL);
HRESULT hr = hrCoInit;
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pIWICFactory);
}
if (SUCCEEDED(hr))
{
// Locate the resource
imageResHandle = FindResourceW(HINST_THISCOMPONENT, resourceName, resourceType);
hr = imageResHandle ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr))
{
// Load the resource
imageResDataHandle = LoadResource(HINST_THISCOMPONENT, imageResHandle);
hr = imageResDataHandle ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr))
{
// Lock it to get a system memory pointer.
pImageFile = LockResource(imageResDataHandle);
hr = pImageFile ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr))
{
// Calculate the size.
imageFileSize = SizeofResource(HINST_THISCOMPONENT, imageResHandle);
hr = imageFileSize ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr))
{
// Create a WIC stream to map onto the memory.
hr = pIWICFactory->CreateStream(&pStream);
}
if (SUCCEEDED(hr))
{
// Initialize the stream with the memory pointer and size.
hr = pStream->InitializeFromMemory(
reinterpret_cast<BYTE*>(pImageFile),
imageFileSize);
}
if (SUCCEEDED(hr))
{
// Create a decoder for the stream.
hr = pIWICFactory->CreateDecoderFromStream(
pStream,
NULL,
WICDecodeMetadataCacheOnLoad,
&pDecoder);
}
if (SUCCEEDED(hr))
{
// Create the initial frame.
hr = pDecoder->GetFrame(0, &pSource);
}
if (SUCCEEDED(hr))
{
// Convert the image format to 32bppPBGRA
// (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).
hr = pIWICFactory->CreateFormatConverter(&pConverter);
}
if (SUCCEEDED(hr))
{
hr = pIWICFactory->CreateBitmapScaler(&pScaler);
}
//.........这里部分代码省略.........
示例5: LoadBitmapFromFile
HRESULT LoadBitmapFromFile(
PCWSTR uri,
UINT dweight,
UINT dheight,
ID2D1Bitmap **bitmap
)
{
HRESULT hr = S_OK;
IWICImagingFactory* pWICFactory = NULL;
IWICBitmapDecoder* pDecoder = NULL;
IWICBitmapScaler* pScaler = NULL;
IWICBitmapFrameDecode* pSource = NULL;
IWICFormatConverter* pConverter = NULL;
hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
(LPVOID*)&pWICFactory);
if (SUCCEEDED(hr))
{
hr = pWICFactory->CreateDecoderFromFilename(
uri,
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnLoad,
&pDecoder);
}
if (SUCCEEDED(hr))
{
hr = pDecoder->GetFrame(0, &pSource);
}
if (SUCCEEDED(hr))
{
hr = pWICFactory->CreateFormatConverter(&pConverter);
}
if (SUCCEEDED(hr))
{
UINT oWeight, oHeight;
hr = pSource->GetSize(&oWeight, &oHeight);
if (SUCCEEDED(hr))
{
hr = pWICFactory->CreateBitmapScaler(&pScaler);
if (SUCCEEDED(hr))
{
hr = pScaler->Initialize(
pSource,
dweight,
dheight,
WICBitmapInterpolationModeCubic);
}
if (SUCCEEDED(hr))
{
hr = pConverter->Initialize(
pScaler,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeMedianCut
);
}
}
}
if (SUCCEEDED(hr))
{
hr = pRT->CreateBitmapFromWicBitmap(pConverter, bitmap);
}
Safe_Release(pWICFactory);
Safe_Release(pDecoder);
Safe_Release(pScaler);
Safe_Release(pSource);
Safe_Release(pConverter);
return hr;
}
示例6: if
//---------------------------------------------------------------------------------
static HRESULT TexImage2DFromWIC(GLenum target, GLint level, IWICBitmapFrameDecode *frame, bool verticalFlip)
{
UINT width, height;
HRESULT hr = frame->GetSize(&width, &height);
if (FAILED(hr))
return hr;
assert(width > 0 && height > 0);
GLint imaxsize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &imaxsize);
assert(imaxsize > 0);
UINT maxsize = static_cast<UINT>(imaxsize);
UINT twidth, theight;
if (width > maxsize || height > maxsize)
{
float ar = static_cast<float>(height) / static_cast<float>(width);
if (width > height)
{
twidth = static_cast<UINT>(maxsize);
theight = static_cast<UINT>(static_cast<float>(maxsize) * ar);
}
else
{
theight = static_cast<UINT>(maxsize);
twidth = static_cast<UINT>(static_cast<float>(maxsize) / ar);
}
assert(twidth <= maxsize && theight <= maxsize);
}
else
{
twidth = width;
theight = height;
}
// Determine format
WICPixelFormatGUID pixelFormat;
hr = frame->GetPixelFormat(&pixelFormat);
if (FAILED(hr))
return hr;
WICPixelFormatGUID convertGUID;
memcpy(&convertGUID, &pixelFormat, sizeof(WICPixelFormatGUID));
size_t bpp = 0;
GLformattype formattype = _WICToGL(pixelFormat);
if (formattype.format == GL_NONE)
{
for (size_t i = 0; i < _countof(g_WICConvert); ++i)
{
if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0)
{
memcpy(&convertGUID, &g_WICConvert[i].target, sizeof(WICPixelFormatGUID));
formattype = _WICToGL(g_WICConvert[i].target);
assert(formattype.format != GL_NONE);
bpp = _WICBitsPerPixel(convertGUID);
break;
}
}
if (formattype.format == GL_NONE)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
else
{
bpp = _WICBitsPerPixel(pixelFormat);
}
if (!bpp)
return E_FAIL;
// Allocate temporary memory for image
size_t rowPitch = (twidth * bpp + 7) / 8;
size_t imageSize = rowPitch * theight;
std::unique_ptr<uint8_t[]> temp(new uint8_t[imageSize]);
// Load image data
if (memcmp(&convertGUID, &pixelFormat, sizeof(GUID)) == 0
&& twidth == width
&& theight == height)
{
// No format conversion or resize needed
hr = CopyPixelsHelper(frame, verticalFlip, 0, static_cast<UINT>(rowPitch), static_cast<UINT>(imageSize), temp.get());
if (FAILED(hr))
return hr;
}
else if (twidth != width || theight != height)
{
// Resize
IWICImagingFactory* pWIC = _GetWIC();
if (!pWIC)
return E_NOINTERFACE;
ComPtr<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler(&scaler);
//.........这里部分代码省略.........
示例7: Initialize
bool Image::Initialize(wchar_t *filename, Graphics *graphics)
{
std::ifstream file;
IWICImagingFactory *pWIC;
IWICStream *stream;
IWICBitmapDecoder *decoder;
IWICBitmapFrameDecode *frame;
unsigned int width, height, twidth, theight, maxsize, bpp, i, support, rowPitch, imageSize;
float ratio;
WICPixelFormatGUID pixelFormat;
DXGI_FORMAT format;
IWICComponentInfo *cinfo;
IWICPixelFormatInfo *pfinfo;
IWICBitmapScaler *scaler;
bool autogen = false;
D3D11_TEXTURE2D_DESC desc;
D3D11_SUBRESOURCE_DATA initData;
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
file.open(filename, std::ios::in | std::ios::binary | std::ios::ate);
if(!file.is_open()) return false;
m_size = file.tellg();
file.seekg(0, std::ios::beg);
m_bytes = new unsigned char [m_size];
file.read((char *)m_bytes, m_size);
file.close();
RETURN_FAIL( CoCreateInstance( CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IWICImagingFactory), (LPVOID*)&pWIC ) );
RETURN_FAIL( pWIC->CreateStream( &stream ) );
RETURN_FAIL( stream->InitializeFromMemory( m_bytes, m_size ) );
RETURN_FAIL( pWIC->CreateDecoderFromStream( stream, 0, WICDecodeMetadataCacheOnDemand, &decoder ) );
RETURN_FAIL( decoder->GetFrame( 0, &frame ) );
RETURN_FAIL( frame->GetSize( &width, &height ) );
SAFE_RELEASE( stream );
SAFE_RELEASE( decoder );
if( width <= 0 || height <= 0 ) return false;
maxsize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
if( width > maxsize || height > maxsize )
{
ratio = static_cast<float>(height) / static_cast<float>(width);
if(width > height)
{
twidth = maxsize;
theight = static_cast<unsigned int>( static_cast<float>(maxsize) * ratio );
}
else
{
theight = maxsize;
twidth = static_cast<unsigned int>( static_cast<float>(maxsize) / ratio );
}
}
else
{
twidth = width;
theight = height;
}
RETURN_FAIL( frame->GetPixelFormat( &pixelFormat ) );
format = DXGI_FORMAT_UNKNOWN;
for( i = 0; i < _countof(g_WICFormats); ++i )
{
if( memcmp( &g_WICFormats[i].wic, &pixelFormat, sizeof(GUID) ) == 0 )
{
format = g_WICFormats[i].dxgi;
break;
}
}
RETURN_FAIL( pWIC->CreateComponentInfo( pixelFormat, &cinfo ) );
RETURN_FAIL( cinfo->QueryInterface( __uuidof(IWICPixelFormatInfo), (LPVOID*)&pfinfo ) );
RETURN_FAIL( pfinfo->GetBitsPerPixel( &bpp ) );
SAFE_RELEASE( cinfo );
SAFE_RELEASE( pfinfo );
RETURN_FAIL( graphics->GetDevice()->CheckFormatSupport( format, &support ) );
if( !(support & D3D11_FORMAT_SUPPORT_TEXTURE2D) ) return false;
rowPitch = ( twidth * bpp + 7 ) / 8;
imageSize = rowPitch * theight;
std::unique_ptr<uint8_t[]> temp( new (std::nothrow) uint8_t[ imageSize ] );
if( !temp ) return false;
if( twidth == width && theight == height )
{
RETURN_FAIL( frame->CopyPixels( 0, rowPitch, imageSize, temp.get() ) );
}
else
{
RETURN_FAIL( pWIC->CreateBitmapScaler( &scaler ) );
RETURN_FAIL( scaler->Initialize( frame, twidth, theight, WICBitmapInterpolationModeFant ) );
//.........这里部分代码省略.........
示例8: LoadResourceImage
/// <summary>
/// Load an image from a resource into a buffer
/// </summary>
/// <param name="resourceName">name of image resource to load</param>
/// <param name="resourceType">type of resource to load</param>
/// <param name="cOutputBuffer">size of output buffer, in bytes</param>
/// <param name="outputBuffer">buffer that will hold the loaded image</param>
/// <returns>S_OK on success, otherwise failure code</returns>
HRESULT KinectEasyGrabber::LoadResourceImage(
PCWSTR resourceName,
PCWSTR resourceType,
DWORD cOutputBuffer,
BYTE* outputBuffer
)
{
HRESULT hr = S_OK;
IWICImagingFactory* pIWICFactory = NULL;
IWICBitmapDecoder* pDecoder = NULL;
IWICBitmapFrameDecode* pSource = NULL;
IWICStream* pStream = NULL;
IWICFormatConverter* pConverter = NULL;
IWICBitmapScaler* pScaler = NULL;
HRSRC imageResHandle = NULL;
HGLOBAL imageResDataHandle = NULL;
void *pImageFile = NULL;
DWORD imageFileSize = 0;
hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pIWICFactory);
if ( FAILED(hr) ) return hr;
// Locate the resource.
imageResHandle = FindResourceW(HINST_THISCOMPONENT, resourceName, resourceType);
hr = imageResHandle ? S_OK : E_FAIL;
if (SUCCEEDED(hr))
{
// Load the resource.
imageResDataHandle = LoadResource(HINST_THISCOMPONENT, imageResHandle);
hr = imageResDataHandle ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr))
{
// Lock it to get a system memory pointer.
pImageFile = LockResource(imageResDataHandle);
hr = pImageFile ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr))
{
// Calculate the size.
imageFileSize = SizeofResource(HINST_THISCOMPONENT, imageResHandle);
hr = imageFileSize ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr))
{
// Create a WIC stream to map onto the memory.
hr = pIWICFactory->CreateStream(&pStream);
}
if (SUCCEEDED(hr))
{
// Initialize the stream with the memory pointer and size.
hr = pStream->InitializeFromMemory(
reinterpret_cast<BYTE*>(pImageFile),
imageFileSize
);
}
if (SUCCEEDED(hr))
{
// Create a decoder for the stream.
hr = pIWICFactory->CreateDecoderFromStream(
pStream,
NULL,
WICDecodeMetadataCacheOnLoad,
&pDecoder
);
}
if (SUCCEEDED(hr))
{
// Create the initial frame.
hr = pDecoder->GetFrame(0, &pSource);
}
if (SUCCEEDED(hr))
{
// Convert the image format to 32bppPBGRA
// (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).
hr = pIWICFactory->CreateFormatConverter(&pConverter);
}
if (SUCCEEDED(hr))
{
hr = pIWICFactory->CreateBitmapScaler(&pScaler);
}
//.........这里部分代码省略.........