本文整理汇总了C++中IWICImagingFactory::CreateDecoderFromFilename方法的典型用法代码示例。如果您正苦于以下问题:C++ IWICImagingFactory::CreateDecoderFromFilename方法的具体用法?C++ IWICImagingFactory::CreateDecoderFromFilename怎么用?C++ IWICImagingFactory::CreateDecoderFromFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWICImagingFactory
的用法示例。
在下文中一共展示了IWICImagingFactory::CreateDecoderFromFilename方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetDefaultCover
/// <summary>
/// Sets the default cover -- when we couldn't find any other cover.
/// </summary>
void CoverArt::SetDefaultCover()
{
IWICImagingFactory *factory = nullptr;
IWICBitmapDecoder *decoder = nullptr;
IWICBitmapFrameDecode *source = nullptr;
HRESULT hr = E_FAIL;
hr = Factories::GetWICFactory(reinterpret_cast<LPVOID*>(&factory));
if (SUCCEEDED(hr))
{
hr = factory->CreateDecoderFromFilename(mDefaultCoverArt, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder);
}
if (SUCCEEDED(hr))
{
hr = decoder->GetFrame(0, &source);
}
if (SUCCEEDED(hr))
{
SendMessage(gLSModule.GetMessageWindow(), WM_COVERARTUPDATE, (WPARAM)this, (LPARAM)source);
}
else
{
SendMessage(gLSModule.GetMessageWindow(), WM_COVERARTUPDATE, (WPARAM)this, (LPARAM)nullptr);
}
SAFERELEASE(decoder);
}
示例2: 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();
}
示例3: SetCoverFromFolder
/// <summary>
/// Tries to get the cover from the specified folder.
/// </summary>
/// <param name="filePath">Path to the file to get the cover from.</param>
bool CoverArt::SetCoverFromFolder(LPCWSTR filePath)
{
WCHAR folderPath[MAX_PATH] = {0};
IWICImagingFactory *factory = nullptr;
IWICBitmapDecoder *decoder = nullptr;
IWICBitmapFrameDecode *source = nullptr;
HRESULT hr = E_FAIL;
StringCchCopyW(folderPath, _countof(folderPath), filePath);
PathRemoveFileSpecW(folderPath);
// Check each covername
WCHAR artPath[MAX_PATH];
for (auto &canidate : mFolderCanidates)
{
StringCchPrintfW(artPath, _countof(artPath), L"%s\\%s", folderPath, canidate.c_str());
for (auto &file : FileIterator(artPath))
{
StringCchPrintfW(artPath, _countof(artPath), L"%s\\%s", folderPath, file.cFileName);
hr = Factories::GetWICFactory(reinterpret_cast<LPVOID*>(&factory));
if (SUCCEEDED(hr))
{
hr = factory->CreateDecoderFromFilename(artPath, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder);
}
if (SUCCEEDED(hr))
{
hr = decoder->GetFrame(0, &source);
}
if (SUCCEEDED(hr))
{
SendMessage(gLSModule.GetMessageWindow(), WM_COVERARTUPDATE, (WPARAM)this, (LPARAM)source);
}
SAFERELEASE(decoder);
if (SUCCEEDED(hr))
{
return true;
}
}
}
return false;
}
示例4:
// ----------------------------------------------------------------
// LoadResource
// ----------------------------------------------------------------
bool CD2DBitmap::LoadResource( ResourceId id )
{
ID2D1HwndRenderTarget * renderTarget = CD2DRenderer::GetInstance().GetHwndRenderTarget();
IWICImagingFactory * imagingFactory = CD2DRenderer::GetInstance().GetImagingFactory();
IWICBitmapDecoder * bitmapDecoder = nullptr;
IWICBitmapFrameDecode* bitmapFrameDecode = nullptr;
imagingFactory->CreateDecoderFromFilename( id.c_str(), nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &bitmapDecoder );
bitmapDecoder->GetFrame( 0, &bitmapFrameDecode );
imagingFactory->CreateFormatConverter( &m_FmtConverter );
m_FmtConverter->Initialize( bitmapFrameDecode, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.0f, WICBitmapPaletteTypeCustom );
renderTarget->CreateBitmapFromWicBitmap( m_FmtConverter, nullptr, &m_D2DBitmap );
SafeRelease( bitmapDecoder );
SafeRelease( bitmapFrameDecode );
return true;
}
示例5: WICTexImage2DFromFile
//---------------------------------------------------------------------------------
HRESULT WICTexImage2DFromFile(GLenum target, GLint level, const wchar_t* fileName, GLboolean verticalFlip)
{
if (!fileName)
{
return E_INVALIDARG;
}
IWICImagingFactory* pWIC = _GetWIC();
if (!pWIC)
return E_NOINTERFACE;
// Initialize WIC
ComPtr<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename(fileName, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder);
if (FAILED(hr))
return hr;
ComPtr<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame(0, &frame);
if (FAILED(hr))
return hr;
return TexImage2DFromWIC(target, level, frame.Get(), !!verticalFlip);
}
示例6: LoadBitmapFromFile
//@https://msdn.microsoft.com/de-de/library/windows/desktop/dd756686(v=vs.85).aspx
HRESULT BitmapDecoder::LoadBitmapFromFile(ID2D1RenderTarget * pRenderTarget, PCWSTR uri, ID2D1Bitmap ** ppBitmap)
{
IWICImagingFactory* pFactory;
HRESULT hr = CoCreateInstance(CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
(LPVOID*)&pFactory
);
//IWICStream *pStream = NULL; //?
//IWICBitmapScaler *pScaler = NULL; //?
IWICBitmapDecoder *pDecoder = NULL;
if (SUCCEEDED(hr))
{
hr = pFactory->CreateDecoderFromFilename(uri, NULL, GENERIC_READ, WICDecodeMetadataCacheOnLoad, &pDecoder);
}
IWICBitmapFrameDecode *pSource = NULL;
if (SUCCEEDED(hr))
{
hr = pDecoder->GetFrame(0, &pSource);
}
IWICFormatConverter *pConverter = NULL;
if (SUCCEEDED(hr))
{
hr = pFactory->CreateFormatConverter(&pConverter);
}
if (SUCCEEDED(hr))
{
hr = pConverter->Initialize(
pSource,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeMedianCut
);
}
if (SUCCEEDED(hr))
{
pRenderTarget->CreateBitmapFromWicBitmap(pConverter, NULL, ppBitmap);
}
if (pDecoder != nullptr)
{
pDecoder->Release();//SafeRelease(&pDecoder);
}
if (pSource != nullptr)
{
pSource->Release();
}
//SafeRelease(&pSource);
// pStream->Release();//SafeRelease(&pStream);
if(pConverter!= nullptr)
{
pConverter->Release();
}
//SafeRelease(&pConverter);
// pScaler->Release();//SafeRelease(&pScaler);
if (pFactory != nullptr)
{
pFactory->Release();
}
return hr;
}
示例7: CreateWICTextureFromFileEx
_Use_decl_annotations_
HRESULT DirectX::CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
ID3D11DeviceContext* d3dContext,
const wchar_t* fileName,
size_t maxsize,
D3D11_USAGE usage,
unsigned int bindFlags,
unsigned int cpuAccessFlags,
unsigned int miscFlags,
bool forceSRGB,
ID3D11Resource** texture,
ID3D11ShaderResourceView** textureView )
{
if ( texture )
{
*texture = nullptr;
}
if ( textureView )
{
*textureView = nullptr;
}
if (!d3dDevice || !fileName || (!texture && !textureView))
return E_INVALIDARG;
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )
return E_NOINTERFACE;
// Initialize WIC
ComPtr<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename( fileName, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, decoder.GetAddressOf() );
if ( FAILED(hr) )
return hr;
ComPtr<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, frame.GetAddressOf() );
if ( FAILED(hr) )
return hr;
hr = CreateTextureFromWIC( d3dDevice, d3dContext, frame.Get(), maxsize,
usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB,
texture, textureView );
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
if ( SUCCEEDED(hr) )
{
if (texture != 0 || textureView != 0)
{
CHAR strFileA[MAX_PATH];
int result = WideCharToMultiByte( CP_ACP,
WC_NO_BEST_FIT_CHARS,
fileName,
-1,
strFileA,
MAX_PATH,
nullptr,
FALSE
);
if ( result > 0 )
{
const CHAR* pstrName = strrchr( strFileA, '\\' );
if (!pstrName)
{
pstrName = strFileA;
}
else
{
pstrName++;
}
if (texture != 0 && *texture != 0)
{
(*texture)->SetPrivateData( WKPDID_D3DDebugObjectName,
static_cast<UINT>( strnlen_s(pstrName, MAX_PATH) ),
pstrName
);
}
if (textureView != 0 && *textureView != 0 )
{
(*textureView)->SetPrivateData( WKPDID_D3DDebugObjectName,
static_cast<UINT>( strnlen_s(pstrName, MAX_PATH) ),
pstrName
);
}
}
}
}
#endif
return hr;
}
示例8: CoCreateInstance
unsigned char *BBWin8Game::LoadImageData( String path,int *pwidth,int *pheight,int *pformat ){
if( !_wicFactory ){
DXASS( CoCreateInstance( CLSID_WICImagingFactory,0,CLSCTX_INPROC_SERVER,__uuidof(IWICImagingFactory),(LPVOID*)&_wicFactory ) );
}
path=PathToFilePath( path );
IWICBitmapDecoder *decoder;
if( !SUCCEEDED( _wicFactory->CreateDecoderFromFilename( path.ToCString<wchar_t>(),NULL,GENERIC_READ,WICDecodeMetadataCacheOnDemand,&decoder ) ) ){
return 0;
}
unsigned char *data=0;
IWICBitmapFrameDecode *bitmapFrame;
DXASS( decoder->GetFrame( 0,&bitmapFrame ) );
UINT width,height;
WICPixelFormatGUID pixelFormat;
DXASS( bitmapFrame->GetSize( &width,&height ) );
DXASS( bitmapFrame->GetPixelFormat( &pixelFormat ) );
if( pixelFormat==GUID_WICPixelFormat24bppBGR ){
unsigned char *t=(unsigned char*)malloc( width*3*height );
DXASS( bitmapFrame->CopyPixels( 0,width*3,width*3*height,t ) );
data=(unsigned char*)malloc( width*4*height );
unsigned char *s=t,*d=data;
int n=width*height;
while( n-- ){
*d++=s[2];
*d++=s[1];
*d++=s[0];
*d++=0xff;
s+=3;
}
free( t );
}else if( pixelFormat==GUID_WICPixelFormat32bppBGRA ){
unsigned char *t=(unsigned char*)malloc( width*4*height );
DXASS( bitmapFrame->CopyPixels( 0,width*4,width*4*height,t ) );
data=t;
int n=width*height;
while( n-- ){ //premultiply alpha
unsigned char r=t[0];
t[0]=t[2]*t[3]/255;
t[1]=t[1]*t[3]/255;
t[2]=r*t[3]/255;
t+=4;
}
}
if( data ){
*pwidth=width;
*pheight=height;
*pformat=4;
}
bitmapFrame->Release();
decoder->Release();
gc_force_sweep=true;
return data;
}
示例9: 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;
}
示例10: Create
HRESULT CRMTexture::Create( std::wstring path )
{
IWICImagingFactory* imageFactory = CRMTextureManager::GetInstance()->GetImageFactory();
IWICBitmapDecoder* bitmapDecoder = nullptr;
HRESULT hr = S_OK;
// 디코더 생성
hr = imageFactory->CreateDecoderFromFilename( path.c_str(), nullptr, GENERIC_READ,
WICDecodeMetadataCacheOnDemand, &bitmapDecoder );
if(FAILED(hr))
return hr;
// 디코더에서 프레임 추출
IWICBitmapFrameDecode* bitmapFrameDecode = nullptr;
hr = bitmapDecoder->GetFrame( 0, &bitmapFrameDecode );
if(FAILED(hr))
{
SafeRelease(bitmapDecoder);
return hr;
}
IWICFormatConverter* formatConverter = nullptr;
// 프레임을 기반으로 컨버터 생성
hr = imageFactory->CreateFormatConverter( &formatConverter );
if(FAILED(hr))
{
SafeRelease(bitmapFrameDecode);
SafeRelease(bitmapDecoder);
return hr;
}
hr = formatConverter->Initialize( bitmapFrameDecode,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone, nullptr, 0.0f,
WICBitmapPaletteTypeCustom );
if(FAILED(hr))
{
SafeRelease(bitmapFrameDecode);
SafeRelease(bitmapDecoder);
}
hr = CRMRender::GetInstance()->GetRenderTarget()->CreateBitmapFromWicBitmap(formatConverter, nullptr, &m_D2D1Bitmap);
if(FAILED(hr))
{
SafeRelease(bitmapFrameDecode);
SafeRelease(bitmapDecoder);
}
m_Width = m_D2D1Bitmap->GetSize().width;
m_Height = m_D2D1Bitmap->GetSize().height;
SafeRelease( bitmapFrameDecode );
SafeRelease( bitmapDecoder );
return hr;
}
示例11: LoadJPG
void LoadJPG(wchar_t *pwszJpg, HWND hwnd)
{
IWICImagingFactory *pFactory = NULL;
HRESULT hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFactory));
if (SUCCEEDED(hr)) {
IWICBitmapDecoder *pDecoder = NULL;
hr = pFactory->CreateDecoderFromFilename(pwszJpg, NULL, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &pDecoder);
if (SUCCEEDED(hr)) {
IWICBitmapFrameDecode *pIDecoderFrame = NULL;
hr = pDecoder->GetFrame(0, &pIDecoderFrame);
if (SUCCEEDED(hr)) {
IWICFormatConverter *pFC = NULL;
hr = pFactory->CreateFormatConverter(&pFC);
hr = pFC->Initialize(pIDecoderFrame, GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeNone, NULL, 0.0, WICBitmapPaletteTypeCustom);
const int nBytesPixel = 3; // GUID_WICPixelFormat24bppBGR 每像素3字节(24bits)
BITMAPINFO bmpInfo;
ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
hr = pIDecoderFrame->GetSize((UINT*)&bmpInfo.bmiHeader.biWidth, (UINT*)&bmpInfo.bmiHeader.biHeight);
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 8 * nBytesPixel;
bmpInfo.bmiHeader.biCompression = BI_RGB;
BYTE *pBuf = NULL;
HDC hdc = GetDC(hwnd);
bmpInfo.bmiHeader.biHeight *= -1; // BMP 方向调整
HBITMAP hBmp = CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, (void**)&pBuf, NULL, 0);
bmpInfo.bmiHeader.biHeight *= -1;
// 计算扫描线
unsigned int cbStride = nBytesPixel * bmpInfo.bmiHeader.biWidth;
unsigned int total = cbStride*bmpInfo.bmiHeader.biHeight;
hr = pFC->CopyPixels(NULL, cbStride, total, pBuf);
// HSL色彩空间变换
DirectX::XMVECTORF32 colorTransofrom = { 1.0f, 1.0f, 1.0f, 1.0f };
if (SUCCEEDED(hr)) {
for (int i = 0; i < bmpInfo.bmiHeader.biHeight; i++) {
for (int j = 0; j < bmpInfo.bmiHeader.biWidth; j++) {
BYTE *pColor = pBuf + cbStride*i + j * nBytesPixel;
DirectX::XMVECTOR colorM = DirectX::PackedVector::XMLoadUByteN4((DirectX::PackedVector::XMUBYTEN4*)pColor);
colorM = DirectX::XMColorRGBToHSL(colorM);
colorM = DirectX::XMColorModulate(colorM, colorTransofrom);
colorM = DirectX::XMColorHSLToRGB(colorM);
DirectX::PackedVector::XMStoreUByteN4((DirectX::PackedVector::XMUBYTEN4*)pColor, colorM);
SetPixel(hdc, j, i, RGB(pColor[2], pColor[1], pColor[0]));
}
}
}
ReleaseDC(hwnd, hdc);
if (SUCCEEDED(hr)) {
MakeMemDC(hBmp, hwnd);
InvalidateRect(hwnd, NULL, TRUE);
}
hr = pFC->Release();
pIDecoderFrame->Release();
}
pDecoder->Release();
}
pFactory->Release();
}
}