本文整理汇总了C++中IWICFormatConverter::GetSize方法的典型用法代码示例。如果您正苦于以下问题:C++ IWICFormatConverter::GetSize方法的具体用法?C++ IWICFormatConverter::GetSize怎么用?C++ IWICFormatConverter::GetSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWICFormatConverter
的用法示例。
在下文中一共展示了IWICFormatConverter::GetSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convert_file_icon
static bool convert_file_icon(const HICON icon, Bmp& bmp) {
static IWICImagingFactory* img_factory = 0;
if (!img_factory) {
// In VS 2011 beta, clsid has to be changed to CLSID_WICImagingFactory1 (from CLSID_WICImagingFactory)
if (!SUCCEEDED(::CoInitialize(0)) || !SUCCEEDED(::CoCreateInstance(CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&img_factory)))) {
return false;
}
}
IWICBitmap* pBitmap = 0;
IWICFormatConverter* pConverter = 0;
UINT cx = 0, cy = 0;
if (SUCCEEDED(img_factory->CreateBitmapFromHICON(icon, &pBitmap))) {
if (SUCCEEDED(img_factory->CreateFormatConverter(&pConverter))) {
if (SUCCEEDED(pConverter->Initialize(pBitmap, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, 0, 0.0f, WICBitmapPaletteTypeCustom))) {
if (SUCCEEDED(pConverter->GetSize(&cx, &cy))) {
const UINT stride = cx * sizeof(DWORD);
const UINT buf_size = cy * stride;
Byte* buf = new Byte[buf_size];
pConverter->CopyPixels(0, stride, buf_size, buf);
bmp.load_bits_only(buf, buf_size, cx, -(int)cy);
delete [] buf;
}
}
pConverter->Release();
}
pBitmap->Release();
}
return true;
}
示例2: processImage
bool WICImageLoader::processImage(IWICBitmapDecoder* pDecoder)
{
HRESULT hr = E_FAIL;
IWICBitmapFrameDecode* pFrame = NULL;
if(NULL != pDecoder)
{
hr = pDecoder->GetFrame(0, &pFrame);
}
if(SUCCEEDED(hr))
{
hr = pFrame->GetPixelFormat(&_format);
}
IWICFormatConverter* pConv = NULL;
if(SUCCEEDED(hr))
{
hr = convertFormatIfRequired(pFrame, &pConv);
}
if(SUCCEEDED(hr))
{
_bpp = getBitsPerPixel(_format);
if(NULL != pConv)
{
hr = pConv->GetSize((UINT*)&_width, (UINT*)&_height);
}
else
{
hr = pFrame->GetSize((UINT*)&_width, (UINT*)&_height);
}
}
assert(_bpp > 0);
assert(_width > 0 && _height > 0);
if(SUCCEEDED(hr))
{
size_t rowPitch = (_width * _bpp + 7) / 8;
_dataLen = rowPitch * _height;
_data = new (std::nothrow) BYTE[_dataLen];
if(NULL != pConv)
{
hr = pConv->CopyPixels(NULL, static_cast<UINT>(rowPitch), static_cast<UINT>(_dataLen), _data);
}
else
{
hr = pFrame->CopyPixels(NULL, static_cast<UINT>(rowPitch), static_cast<UINT>(_dataLen), _data);
}
}
SafeRelease(&pFrame);
SafeRelease(&pConv);
return SUCCEEDED(hr);
}
示例3: LoadResourceImage
//.........这里部分代码省略.........
}
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);
}
if (SUCCEEDED(hr))
{
hr = pScaler->Initialize(
pSource,
nOutputWidth,
nOutputHeight,
WICBitmapInterpolationModeCubic
);
}
if (SUCCEEDED(hr))
{
hr = pConverter->Initialize(
pScaler,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeMedianCut);
}
UINT width = 0;
UINT height = 0;
if (SUCCEEDED(hr))
{
hr = pConverter->GetSize(&width, &height);
}
// make sure the image scaled correctly so the output buffer is big enough
if (SUCCEEDED(hr))
{
if ((width != nOutputWidth) || (height != nOutputHeight))
{
hr = E_FAIL;
}
}
if (SUCCEEDED(hr))
{
hr = pConverter->CopyPixels(NULL, width * sizeof(RGBQUAD), nOutputWidth * nOutputHeight * sizeof(RGBQUAD), reinterpret_cast<BYTE*>(pOutputBuffer));
}
SafeRelease(pScaler);
SafeRelease(pConverter);
SafeRelease(pSource);
SafeRelease(pDecoder);
SafeRelease(pStream);
SafeRelease(pIWICFactory);
if (SUCCEEDED(hrCoInit))
{
CoUninitialize();
}
return hr;
}
示例4: LoadResourceImage
//.........这里部分代码省略.........
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);
}
if (SUCCEEDED(hr))
{
hr = pScaler->Initialize(
pSource,
m_colorWidth,
m_colorHeight,
WICBitmapInterpolationModeCubic
);
}
if (SUCCEEDED(hr))
{
hr = pConverter->Initialize(
pScaler,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeMedianCut
);
}
UINT width = 0;
UINT height = 0;
if (SUCCEEDED(hr))
{
hr = pConverter->GetSize(&width, &height);
}
// make sure the output buffer is large enough
if (SUCCEEDED(hr))
{
if ( width*height*cBytesPerPixel > cOutputBuffer )
{
hr = E_FAIL;
}
}
if (SUCCEEDED(hr))
{
hr = pConverter->CopyPixels(NULL, width*cBytesPerPixel, cOutputBuffer, outputBuffer);
}
SafeRelease(pScaler);
SafeRelease(pConverter);
SafeRelease(pSource);
SafeRelease(pDecoder);
SafeRelease(pStream);
SafeRelease(pIWICFactory);
return hr;
}