当前位置: 首页>>代码示例>>C++>>正文


C++ IWICFormatConverter::Initialize方法代码示例

本文整理汇总了C++中IWICFormatConverter::Initialize方法的典型用法代码示例。如果您正苦于以下问题:C++ IWICFormatConverter::Initialize方法的具体用法?C++ IWICFormatConverter::Initialize怎么用?C++ IWICFormatConverter::Initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IWICFormatConverter的用法示例。


在下文中一共展示了IWICFormatConverter::Initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ConvertBitmapSource

HRESULT ConvertBitmapSource( RECT rcDest, IWICBitmapSource*& pToRenderBitmapSource )
{
	HRESULT hr = S_OK;
	IWICBitmapScaler* pScaler = nullptr;
	WICPixelFormatGUID pxformat;
	IWICFormatConverter* pConverter = nullptr;

	pToRenderBitmapSource = nullptr;

	// Get the client Rect
	//RECT rcClient = rcDest;
	//hr = GetClientRect(hWnd, &rcClient) ? S_OK: E_FAIL;

	if( SUCCEEDED( hr ) )
	{
		// Create a BitmapScaler
		hr = g_UserImageFactoryInst.m_pIWICFactory->CreateBitmapScaler( &pScaler );
		//hr = IWICImagingFactory_CreateBitmapScaler( g_UserImageFactoryInst.m_pIWICFactory, &pScaler );

		// Initialize the bitmap scaler from the original bitmap map bits
		if( SUCCEEDED( hr ) )
		{
			pScaler->Initialize( g_UserImageFactoryInst.m_pOriginalBitmapSource,
								 rcDest.right - rcDest.left,
								 rcDest.bottom - rcDest.top,
								 WICBitmapInterpolationModeFant );
		}

		//hr = IWICBitmapScaler_GetPixelFormat( pScaler, &pxformat );
		hr = pScaler->GetPixelFormat( &pxformat );

		// Format convert the bitmap into 32bppBGR, a convenient 
		// pixel format for GDI rendering 
		if( SUCCEEDED( hr ) )
		{
			//hr = IWICImagingFactory_CreateFormatConverter( g_UserImageFactoryInst.m_pIWICFactory, &pConverter );
			hr = g_UserImageFactoryInst.m_pIWICFactory->CreateFormatConverter( &pConverter );

			// Format convert to 32bppBGR
			if( SUCCEEDED( hr ) )
			{
				hr = pConverter->Initialize( static_cast<IWICBitmapSource*>( pScaler ),	// Input bitmap to convert
											 GUID_WICPixelFormat32bppBGR,				//	&GUID_WICPixelFormat32bppBGR,
											 WICBitmapDitherTypeNone,					// Specified dither patterm
											 NULL,										// Specify a particular palette 
											 0.f,										// Alpha threshold
											 WICBitmapPaletteTypeCustom );				// Palette translation type

				// Store the converted bitmap as ppToRenderBitmapSource 
				if( SUCCEEDED( hr ) )
					pConverter->QueryInterface( IID_IWICBitmapSource, reinterpret_cast<void**>( &pToRenderBitmapSource ) );
			}
			SAFE_RELEASE( pConverter );
		}

		SAFE_RELEASE( pScaler );
	}

	return hr;
}
开发者ID:ddugovic,项目名称:RASuite,代码行数:60,代码来源:RA_ImageFactory.cpp

示例2: 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;
    }
开发者ID:pawelt,项目名称:stacky,代码行数:29,代码来源:stacky.cpp

示例3: LoadBitmapFromFile

HRESULT Game::LoadBitmapFromFile(LPCTSTR strFileName, ID2D1Bitmap** ppBitmap)
{
	HRESULT hr;

	IWICBitmapDecoder *pDecoder = NULL;
	IWICBitmapFrameDecode *pSource = NULL;
	IWICFormatConverter *pConverter = NULL;

	hr = pWICFactory->CreateDecoderFromFilename(strFileName, NULL, GENERIC_READ, WICDecodeMetadataCacheOnLoad, &pDecoder);
	if (SUCCEEDED(hr))
	{
		hr = pDecoder->GetFrame(0, &pSource);
	}
	if (SUCCEEDED(hr))
	{
		hr = pWICFactory->CreateFormatConverter(&pConverter);
	}
	if (SUCCEEDED(hr))
	{
		hr = pConverter->Initialize(pSource, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, NULL, 0.f, WICBitmapPaletteTypeMedianCut);
	}
	if (SUCCEEDED(hr))
	{
		hr = pRT->CreateBitmapFromWicBitmap(pConverter, NULL, ppBitmap);
	}
	SafeRelease(&pDecoder);
	SafeRelease(&pSource);
	SafeRelease(&pConverter);
	return hr;
}
开发者ID:UsefulEndymion,项目名称:Project2,代码行数:30,代码来源:Game.cpp

示例4: CoCreateInstance

SpriteSheet::SpriteSheet(wchar_t* filename, Graphics* gfx)
{
	this->gfx = gfx;
	bmp = NULL;
	HRESULT hr;

	//create a wic factory 
	IWICImagingFactory *wicFactory = NULL;
	hr = CoCreateInstance(
		CLSID_WICImagingFactory,
		NULL,
		CLSCTX_INPROC_SERVER,
		IID_IWICImagingFactory,
		(LPVOID*)&wicFactory);

	//create a decoder
	IWICBitmapDecoder *wicDecoder = NULL;
	hr = wicFactory->CreateDecoderFromFilename(
		filename,       // THE FILE NAME
		NULL,           // the preferred vendor
		GENERIC_READ,   // we're reading the file, not writing
		WICDecodeMetadataCacheOnLoad,
		&wicDecoder);

	// read a frame from the image
	IWICBitmapFrameDecode* wicFrame = NULL;
	hr = wicDecoder->GetFrame(0, &wicFrame);

	// create a converter
	IWICFormatConverter *wicConverter = NULL;
	hr = wicFactory->CreateFormatConverter(&wicConverter);

	// setup the converter
	hr = wicConverter->Initialize(
		wicFrame,                      // frame
		GUID_WICPixelFormat32bppPBGRA, // pixel format
		WICBitmapDitherTypeNone,       // irrelevant
		NULL,             // no palette needed, irrlevant
		0.0,              // alpha transparency % irrelevant
		WICBitmapPaletteTypeCustom     // irrelevant
		);

	// use the converter to create an D2D1Bitmap
	/// ID2D1Bitmap* bmp;      // this will be a member variable
	hr = gfx->GetRenderTarget()->CreateBitmapFromWicBitmap(
		wicConverter,      // converter
		NULL,              // D2D1_BITMAP_PROPERIES
		&bmp               // destiatnion D2D1 bitmap
		);

	if (wicFactory) wicFactory->Release();
	if (wicDecoder) wicDecoder->Release();
	if (wicConverter) wicConverter->Release();
	if (wicFrame) wicFrame->Release();

}
开发者ID:SneakyRopes,项目名称:Sneaky-Ropes-v3,代码行数:56,代码来源:SpriteSheet.cpp

示例5: ConvertWICBitmapFormat

//etc. WICConvertBitmapSource
BOOL ConvertWICBitmapFormat(IWICImagingFactory* pWICFactory,REFWICPixelFormatGUID toFormat,IWICBitmapSource* pSrc,IWICBitmapSource** ppDst)
{
	IWICFormatConverter* pWICFormatConverter;
	if (FAILED(pWICFactory->CreateFormatConverter(&pWICFormatConverter)))
		return FALSE;
	if (SUCCEEDED(pWICFormatConverter->Initialize(pSrc,toFormat,WICBitmapDitherTypeNone,NULL,.0f,WICBitmapPaletteTypeCustom)))
	{
		*ppDst = pWICFormatConverter;
		return TRUE;
	}
	return FALSE;
}
开发者ID:CHANAYA,项目名称:WinPhoneProjection,代码行数:13,代码来源:D2DRenderWindowHelp.cpp

示例6: convertFormatIfRequired

HRESULT WICImageLoader::convertFormatIfRequired(IWICBitmapFrameDecode* pFrame, IWICFormatConverter** ppConv)
{
	*ppConv = NULL;

	if(	(memcmp(&_format, &GUID_WICPixelFormat8bppGray, sizeof(WICPixelFormatGUID)) == 0) ||
		(memcmp(&_format, &GUID_WICPixelFormat8bppAlpha, sizeof(WICPixelFormatGUID)) == 0) ||
		(memcmp(&_format, &GUID_WICPixelFormat24bppRGB, sizeof(WICPixelFormatGUID)) == 0) ||
		(memcmp(&_format, &GUID_WICPixelFormat32bppRGBA, sizeof(WICPixelFormatGUID)) == 0))
	{
		return S_OK;
	}

	HRESULT hr = E_FAIL;
	IWICImagingFactory* pFactory = getWICFactory();
	IWICFormatConverter* pConv = NULL;

	if(NULL != pFactory)
	{
		hr = pFactory->CreateFormatConverter(&pConv);
	}

	WICPixelFormatGUID destFormat = GUID_WICPixelFormat32bppRGBA; // Fallback to RGBA 32-bit format which is supported by all devices

	for( size_t i=0; i < _countof(g_WICConvert); ++i )
	{
		if ( memcmp( &g_WICConvert[i].source, &_format, sizeof(WICPixelFormatGUID) ) == 0 )
		{
			memcpy( &destFormat, &g_WICConvert[i].target, sizeof(WICPixelFormatGUID) );
			break;
		}
	}

	BOOL bCanConv = FALSE;

	if(SUCCEEDED(hr))
	{
		hr = pConv->CanConvert(_format, destFormat, &bCanConv);
	}

	if(SUCCEEDED(hr) && bCanConv == TRUE)
	{
		hr = pConv->Initialize(pFrame, destFormat, WICBitmapDitherTypeErrorDiffusion, 0, 0, WICBitmapPaletteTypeCustom);
	}

	if(SUCCEEDED(hr))
	{
		memcpy(&_format, &destFormat, sizeof(WICPixelFormatGUID));
		*ppConv = pConv;
	}

	return SUCCEEDED(hr);
}
开发者ID:602147629,项目名称:PlanetWar,代码行数:52,代码来源:WICImageLoader-winrt.cpp

示例7:

HRESULT d2d::LoadBitmap (
	const wchar_t* filename,
	IWICImagingFactory* wic,
	ID2D1RenderTarget* rt,
	ID2D1Bitmap **bitmap )
{
	HRESULT hr = S_OK;
	IWICBitmapFrameDecode *frame = nullptr;
	IWICBitmapDecoder *decoder = nullptr;
	IWICFormatConverter *conv = nullptr;
 
	// 디코더 생성
	hr = wic->CreateDecoderFromFilename (
			filename,
			0,
			GENERIC_READ,
			WICDecodeMetadataCacheOnDemand,
			&decoder );
 
	// 프레임 얻기
	if(SUCCEEDED(hr))
		hr = decoder->GetFrame (0, &frame);
 
	// 변환기 생성
	if(SUCCEEDED(hr))
		hr = wic->CreateFormatConverter(&conv);
	
	// 변환기 초기화
	if(SUCCEEDED(hr))
		hr = conv->Initialize (
				frame,
				GUID_WICPixelFormat32bppPBGRA,
				WICBitmapDitherTypeNone,
				0,
				1.0f,
				WICBitmapPaletteTypeCustom );
 
	// 비트맵 생성
	if(SUCCEEDED(hr))
		hr = rt->CreateBitmapFromWicBitmap (
				conv,
				bitmap );
	
	// 해제
	d2d::SafeRelease(frame);
	d2d::SafeRelease(decoder);
	d2d::SafeRelease(conv);
 
	// 결과 반환
	return hr;
}
开发者ID:KimHeeKue,项目名称:Unipen,代码行数:51,代码来源:d2dutils.cpp

示例8: SafeRelease

//从一个文件加载图片
ID2D1Bitmap* d2d::CreateBitmapFromFile(wstring strFileName)
{
    IWICBitmapDecoder *pDecoder = nullptr;
    HRESULT hr = m_pWICFactory->CreateDecoderFromFilename(strFileName.c_str(), NULL, GENERIC_READ,
                                                          WICDecodeMetadataCacheOnLoad, //enum WICDecodeOptions
                                                          &pDecoder);

    if (FAILED(hr))
    {
        return nullptr;
    }

     // Create the initial frame.
    IWICBitmapFrameDecode *pSource = nullptr;
    hr = pDecoder->GetFrame(0, &pSource);
    if (FAILED(hr))
    {
        return nullptr;
    }

    //转换器
    IWICFormatConverter *pConverter = nullptr;
    hr = m_pWICFactory->CreateFormatConverter(&pConverter);
    if (FAILED(hr))
    {
        return nullptr;
    }

    hr = pConverter->Initialize(pSource, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone,
                                NULL, 0.f, WICBitmapPaletteTypeMedianCut);
 
    if (FAILED(hr))
    {
        return nullptr;
    }
    
    // Create a Direct2D bitmap from the WIC bitmap.
    ID2D1Bitmap* picBitmap = nullptr;
    hr = m_pRenderTarget->CreateBitmapFromWicBitmap(pConverter, NULL, &picBitmap);
    if (FAILED(hr))
    {
        return nullptr;
    }

    SafeRelease(pDecoder);
    SafeRelease(pSource);
    SafeRelease(pConverter);

    return picBitmap;
}
开发者ID:wangzhimin,项目名称:WzmPoker,代码行数:51,代码来源:d2d.cpp

示例9:

	BitmapWrapperD2D::BitmapWrapperD2D(bitmap bmp)
	{
		IWICBitmap* wic = 0;

		Graphics::locator.getfactory()->CreateBitmapFromMemory(
			bmp.width(), bmp.height(),
			GUID_WICPixelFormat32bppBGRA,
			4 * bmp.width(),
			bmp.length(),
			(BYTE*)bmp.data(),
			&wic);

		if (wic != 0)
		{
			IWICFormatConverter* converter = nullptr;
			IWICBitmap* temp = nullptr;
			int result = Graphics::locator.getfactory()->CreateFormatConverter(&converter);
			if (result == 0)
			{
				converter->Initialize(wic,
					GUID_WICPixelFormat32bppPBGRA,
					WICBitmapDitherTypeNone, 0, 0.f,
					WICBitmapPaletteTypeMedianCut);
				Graphics::locator.getfactory()->CreateBitmapFromSource(converter, WICBitmapNoCache, &temp);
				converter->Release();
			}
			wic->Release();

			ID2D1BitmapRenderTarget* target = Graphics::locator.gettarget();
			if (target)
			{
				target->CreateBitmapFromWicBitmap(temp, &source);
				temp->Release();
				temp = nullptr;
			}
			else
			{
				source = nullptr;
			}
		}
		else
		{
			source = nullptr;
		}
	}
开发者ID:pandaforks,项目名称:JourneyClient,代码行数:45,代码来源:BitmapWrapperD2D.cpp

示例10: LoadBitmapFromFile

// =========================================================
// Load the specified bitmap from file into D2D bitmap
// =========================================================
BOOL Loader::LoadBitmapFromFile(LPCWSTR filename, const Graphics* graphicsWrapper, ID2D1Bitmap** ppBitmap)
{
	if (!isInitialized)
		return FALSE;

	HRESULT hr;

	IWICBitmapDecoder *pDecoder = NULL;
	IWICBitmapFrameDecode *pSource = NULL;
	IWICFormatConverter *pConverter = NULL;

	hr = pFactory->CreateDecoderFromFilename(filename, NULL, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &pDecoder);
	CHECK(failedDecoder);

	hr = pDecoder->GetFrame(0, &pSource);
	CHECK(failedGetFrame);

	hr = pFactory->CreateFormatConverter(&pConverter);
	CHECK(failedConverter);

	hr = pConverter->Initialize(pSource, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, NULL, 0.0, WICBitmapPaletteTypeMedianCut);
	CHECK(failedConversion);

	hr = graphicsWrapper->pRenderTarget->CreateBitmapFromWicBitmap(pSource, ppBitmap);
	CHECK(failedBitmap);

	return TRUE;

failedBitmap:
	OutputDebugStringA("Loader::LoadBitmapFromFile -> Failed to create bitmap.\n");
failedConversion:
	pConverter->Release();
	OutputDebugStringA("Loader::LoadBitmapFromFile -> Failed to initialise format converter.\n");
failedConverter:
	pSource->Release();
	OutputDebugStringA("Loader::LoadBitmapFromFile -> Failed to create format converter.\n");
failedGetFrame:
	pDecoder->Release();
	OutputDebugStringA("Loader::LoadBitmapFromFile -> Failed to get frame 0 from source bitmap.\n");
failedDecoder:
	OutputDebugStringA("Loader::LoadBitmapFromFile -> Failed to create bitmap decoder.\n");
	return FALSE;
}
开发者ID:beelee93,项目名称:MinesweeperDX,代码行数:46,代码来源:Loader.cpp

示例11: make_pair

	pair<imgcontext, size_t> imagecache::createimage(bitmap bmp)
	{
		size_t id = bmp.id();

		if (temp[imgcon][id] || cache[imgcon][id])
		{
			return make_pair(imgcon, id);
		}
		else
		{
			IWICBitmap* wic = 0;

			imgfactory->CreateBitmapFromMemory(
				bmp.width(), bmp.height(),
				GUID_WICPixelFormat32bppBGRA,
				4 * bmp.width(),
				bmp.length(),
				(BYTE*)bmp.data(),
				&wic);

			if (wic)
			{
				IWICFormatConverter* spConverter = 0;
				int result = imgfactory->CreateFormatConverter(&spConverter);
				if (result == 0)
				{
					spConverter->Initialize(wic, 
						GUID_WICPixelFormat32bppPBGRA,
						WICBitmapDitherTypeNone, NULL, 0.f,
						WICBitmapPaletteTypeMedianCut);
					imgfactory->CreateBitmapFromSource(spConverter, WICBitmapNoCache, &temp[imgcon][id]);
					spConverter->Release();
				}
				wic->Release();
			}
		}

		return make_pair(imgcon, id);
	}
开发者ID:thisIsTooHard,项目名称:journey_client,代码行数:39,代码来源:imagecache.cpp

示例12: SHCreateMemStream

void GL::Image::load(const unsigned char *buf, size_t bufSize)
{
    if (CoInitializeEx(NULL, COINIT_MULTITHREADED) != S_OK) {
        // bad!
        return;
    }
    IStream *stream = SHCreateMemStream((const BYTE*)buf, (UINT)bufSize);
    if (stream != NULL) {
        IWICImagingFactory *pFactory;
        if (CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pFactory) == S_OK) {
            IWICBitmapDecoder *pDecoder;
            if (pFactory->CreateDecoderFromStream(stream, &CLSID_WICPngDecoder, WICDecodeMetadataCacheOnDemand, &pDecoder) == S_OK) {
                IWICBitmapFrameDecode *frame;
                if (pDecoder->GetFrame(0, &frame) == S_OK) {
                    UINT w, h;
                    if (frame->GetSize(&w, &h) == S_OK) {
                        width_ = w;
                        height_ = h;
                    }
                    IWICFormatConverter *formatConverter;
                    if (pFactory->CreateFormatConverter(&formatConverter) == S_OK) {
                        if (formatConverter->Initialize(frame, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom) == S_OK) {
                            unsigned char *pixels = new unsigned char[w * h * 4];
                            if (formatConverter->CopyPixels(0, w * 4, w * h * 4, pixels) == S_OK) {
                                loadTextureData_(pixels);
                            }
                            delete[] pixels;
                        }
                        formatConverter->Release();
                    }
                }
                pDecoder->Release();
            }
            pFactory->Release();
        }
        stream->Release();
    }
    CoUninitialize();
}
开发者ID:MaddTheSane,项目名称:Glypha,代码行数:39,代码来源:GLImage_Win32.cpp

示例13: Commit

STDMETHODIMP BaseFrameEncode::Commit()
{
    HRESULT result = S_OK;
    
    IWICBitmapScaler *scaler = NULL;
    IWICFormatConverter *formatConverter = NULL;

    result = S_OK;

    // Create a scaler to match the requested width and height
    if (SUCCEEDED(result))
        {
        result = factory->CreateBitmapScaler(&scaler);
    }

    if (SUCCEEDED(result))
    {
        result = scaler->Initialize(destSource, destWidth, destHeight, WICBitmapInterpolationModeFant);
    }

    // Create a format converter to output into the proper format
    if (SUCCEEDED(result))
    {
        result = factory->CreateFormatConverter(&formatConverter);
    }
    if (SUCCEEDED(result))
    {
        result = formatConverter->Initialize(scaler, destPixelFormat, WICBitmapDitherTypeErrorDiffusion,
            destPalette, 50.0, WICBitmapPaletteTypeCustom);
    }

    // Cleanup
    if (formatConverter)
    {
        destSource->Release();
        destSource = formatConverter;
    }    
    return result;
}
开发者ID:AhFu,项目名称:WPF-Samples,代码行数:39,代码来源:BaseEncoder.cpp

示例14: LoadResourceBitmap

HRESULT LoadResourceBitmap(
	ID2D1RenderTarget* pRendertarget,
	IWICImagingFactory* pIWICFactory,
	PCWSTR resourceName,
	PCWSTR resourceType,
	UINT destinationWidth,
	UINT destinationHeight,
	ID2D1Bitmap** ppBitmap
	)
{
	HRESULT hr = S_OK;

	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;

	// Find the resource then load it
	imageResHandle = FindResource(HINST_THISCOMPONENT, resourceName, resourceType);
	hr = imageResHandle ? S_OK : E_FAIL;
	if (SUCCEEDED(hr))
	{
		imageResDataHandle = LoadResource(HINST_THISCOMPONENT, imageResHandle);

		hr = imageResDataHandle ? S_OK : E_FAIL;
	}

	// Lock the resource and calculate the image's size
	if (SUCCEEDED(hr))
	{
		// Lock it to get the 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;
	}

	// Create an IWICStream object
	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
			);
	}

	// Create IWICBitmapDecoder
	if (SUCCEEDED(hr))
	{
		// Create a decoder for the stream
		hr = pIWICFactory->CreateDecoderFromStream(
			pStream,
			NULL,
			WICDecodeMetadataCacheOnLoad,
			&pDecoder
			);
	}

	// Retrieve a frame from the image and store it in an IWICBitmapFrameDecode object
	if (SUCCEEDED(hr))
	{
		// Create the initial frame
		hr = pDecoder->GetFrame(0, &pSource);
	}

	// Before Direct2D can use the image, it must be converted to the 32bppPBGRA pixel format.
	// To convert the image format, use the IWICImagingFactory::CreateFormatConverter method to create an IWICFormatConverter object, then use the IWICFormatConverter object's Initialize method to perform the conversion.
	if (SUCCEEDED(hr))
	{
		// Convert the image format to 32bppPBGRA
		// (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).
		hr = pIWICFactory->CreateFormatConverter(&pConverter);
	}

	if (SUCCEEDED(hr))
	{
		// If a new width or height was specified, create and
		// IWICBitmapScaler and use it to resize the image.
		if (destinationWidth != 0 || destinationHeight != 0)
		{
			UINT originalWidth;
//.........这里部分代码省略.........
开发者ID:codepongo,项目名称:iBurnMgr,代码行数:101,代码来源:MetroWindow.cpp

示例15: 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);
    }
//.........这里部分代码省略.........
开发者ID:starwada,项目名称:K4W_Sample,代码行数:101,代码来源:CoordinateMappingBasics.cpp


注:本文中的IWICFormatConverter::Initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。