本文整理汇总了C++中Bitmap::GetHBITMAP方法的典型用法代码示例。如果您正苦于以下问题:C++ Bitmap::GetHBITMAP方法的具体用法?C++ Bitmap::GetHBITMAP怎么用?C++ Bitmap::GetHBITMAP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitmap
的用法示例。
在下文中一共展示了Bitmap::GetHBITMAP方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadBitmapFromFile
// 读取图片(从文件读)
BOOL LoadBitmapFromFile(const CString strPathFile, CBitmap &bitmap, CSize &size)
{
HBITMAP hBitmap = NULL;
#ifdef _UNICODE
Bitmap* pBitmap = Bitmap::FromFile(strPathFile);
#else
Bitmap* pBitmap = Bitmap::FromFile(CEncodingUtil::AnsiToUnicode(strPathFile));
#endif
Status status = pBitmap->GetLastStatus();
if(Ok == status)
{
status = pBitmap->GetHBITMAP(Color(0,0,0), &hBitmap);
if(Ok == status)
{
if(bitmap.m_hObject != NULL)
{
bitmap.Detach();
}
bitmap.Attach(hBitmap);
BITMAP bmInfo;
::GetObject( bitmap.m_hObject, sizeof(BITMAP), &bmInfo );
size.cx = bmInfo.bmWidth;
size.cy = bmInfo.bmHeight;
delete pBitmap;
return TRUE;
}
}
return FALSE;
}
示例2: RenderedBitmap
RenderedBitmap *LoadRenderedBitmap(const WCHAR *filePath)
{
if (str::EndsWithI(filePath, L".bmp")) {
HBITMAP hbmp = (HBITMAP)LoadImage(NULL, filePath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (!hbmp)
return NULL;
return new RenderedBitmap(hbmp, GetBitmapSize(hbmp));
}
size_t len;
ScopedMem<char> data(file::ReadAll(filePath, &len));
if (!data)
return NULL;
Bitmap *bmp = BitmapFromData(data, len);
if (!bmp)
return NULL;
HBITMAP hbmp;
RenderedBitmap *rendered = NULL;
if (bmp->GetHBITMAP(Color::White, &hbmp) == Ok)
rendered = new RenderedBitmap(hbmp, SizeI(bmp->GetWidth(), bmp->GetHeight()));
delete bmp;
return rendered;
}
示例3: AddImageList
int CShoshTreeCtrl::AddImageList(const char* stfilePath)
{
bool bRet= m_xImage->Load(stfilePath,CXIMAGE_FORMAT_PNG);
CDC *pDC = GetDC();
Bitmap * pbmp = GetNewBitmap(stfilePath);
if (pbmp == NULL) return -1;
m_pBitMapList2.push_back(pbmp);
Color cr = Color::White;
HBITMAP hBitmap = NULL ;//m_xImage->MakeBitmap(pDC->GetSafeHdc());
pbmp->GetHBITMAP( cr, &hBitmap );
if ( NULL != hBitmap )
{
CBitmap* pBitmap;
pBitmap = new CBitmap;
m_pBitMapList.push_back(pBitmap);
pBitmap->Attach(hBitmap);
int nRetNum = m_ImageList.Add(pBitmap,RGB(0,0,0));
return nRetNum;
}
return -1;
}
示例4: size
virtual RenderedBitmap *GetImage() {
HBITMAP hbmp;
Bitmap *bmp = BitmapFromData(id->data, id->len);
if (!bmp || bmp->GetHBITMAP(Color::White, &hbmp) != Ok) {
delete bmp;
return NULL;
}
SizeI size(bmp->GetWidth(), bmp->GetHeight());
delete bmp;
return new RenderedBitmap(hbmp, size);
}
示例5: LoadBitmapFromIDResource
// 读取图片(从资源读)
BOOL LoadBitmapFromIDResource(UINT nID, CBitmap &bitmap, CSize &size, CString strType)
{
HINSTANCE hInst = AfxGetResourceHandle();
HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID), strType);
if (!hRsrc)
{
return FALSE;
}
DWORD len = SizeofResource(hInst, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
if (!lpRsrc)
{
return FALSE;
}
HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
memcpy(pmem,lpRsrc,len);
IStream* pstm;
CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);
Bitmap* pBitmap = Gdiplus::Bitmap::FromStream(pstm);
GlobalUnlock(m_hMem);
GlobalFree(m_hMem);
pstm->Release();
FreeResource(lpRsrc);
HBITMAP hBitmap = NULL;
Status status = pBitmap->GetLastStatus();
if(Ok == status)
{
status = pBitmap->GetHBITMAP(Color(0,0,0), &hBitmap);
delete pBitmap;
if(Ok == status)
{
if(bitmap.m_hObject != NULL)
{
bitmap.Detach();
}
bitmap.Attach(hBitmap);
BITMAP bmInfo;
::GetObject( bitmap.m_hObject, sizeof(BITMAP), &bmInfo );
size.cx = bmInfo.bmWidth;
size.cy = bmInfo.bmHeight;
return TRUE;
}
}
return FALSE;
}
示例6: GDIPlus_LoadGlyphImage
HBITMAP GDIPlus_LoadGlyphImage(const wchar_t *tszFileName)
{
// Create a Bitmap object from a JPEG file.
Bitmap bitmap(tszFileName, 0);
// Clone a portion of the bitmap.
Bitmap* clone = bitmap.Clone(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), PixelFormat32bppPARGB);
HBITMAP hbmp = nullptr;
if (clone) {
clone->GetHBITMAP(Color(0, 0, 0), &hbmp);
delete clone;
}
return hbmp;
}
示例7: LoadImageFromBuffer
LIBELCBASEUI_API BOOL LoadImageFromBuffer(LPBYTE lpBuffer, int cbBuffer, CBitmap* pBitmap, CSize& size)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (!lpBuffer || cbBuffer <= 0 || !pBitmap)
return FALSE;
IStream* pstm = NULL;
Bitmap *pImage = NULL;
BOOL bSuccessful = FALSE;
PBYTE pMem = NULL;
HGLOBAL hMem = NULL;
do
{
hMem = GlobalAlloc(GMEM_FIXED, cbBuffer);
pMem = (BYTE*)GlobalLock(hMem);
memcpy(pMem, lpBuffer, cbBuffer);
CreateStreamOnHGlobal(hMem, FALSE, &pstm);
pImage = Bitmap::FromStream(pstm);
if (!pImage || pImage->GetLastStatus() != Ok)
break;
HBITMAP hBitmap = NULL;
pImage->GetHBITMAP(Color::White, &hBitmap);
pBitmap->DeleteObject();
if (!pBitmap->Attach(hBitmap))
break;
BITMAP bm;
GetObject(pBitmap->m_hObject, sizeof(bm), &bm);
size.cx = pImage->GetWidth();
size.cy = pImage->GetHeight();
bSuccessful = TRUE;
} while (0);
if (hMem)
GlobalUnlock(hMem);
if (pstm)
pstm->Release();
if (pImage)
delete pImage;
return bSuccessful;
}
示例8: OnLoadImages
void CCxLoginBar::OnLoadImages ()
{
//static const int cxImg = 16;
//static const int cyImg = 16;
static const LPCTSTR arrImageName[] = {
"User.png",
"Login.png", "login_Pressed.png", "login_Focused.png",
"Logout.png", "logout_Pressed.png", "logout_Focused.png"
};
CString strDir = GetExecDir() + "\\Res\\Login\\";
Bitmap * pBitmap = NULL;
HBITMAP hbmp = NULL;
//ResetAll();
ClearImages();
Color crImgBg;
crImgBg.SetFromCOLORREF(g_crToolbarBg);
//m_BCGToolbarImages.SetImageSize( CSize(cxImg, cyImg) );
m_BCGToolbarImages.SetTransparentColor (g_crToolbarBg);
int nCount = sizeof( arrImageName ) / sizeof( LPCTSTR );
for (int i=0; i<nCount; i++)
{
pBitmap = GetNewBitmap( strDir + arrImageName[i] );
if ( pBitmap == NULL )
{
ClearImages();
return;
}
m_vImages.push_back( pBitmap );
pBitmap->GetHBITMAP( crImgBg, &hbmp);
if ( hbmp == NULL )
{
ClearImages();
return;
}
m_vHBitmaps.push_back( hbmp );
m_BCGToolbarImages.AddImage( hbmp );
}
if ( m_BCGToolbarImages.GetCount() == 0 ) return;
}
示例9: data
static RenderedBitmap *LoadRenderedBitmap(const WCHAR *filePath)
{
size_t len;
ScopedMem<char> data(file::ReadAll(filePath, &len));
if (!data)
return NULL;
Bitmap *bmp = BitmapFromData(data, len);
if (!bmp)
return NULL;
HBITMAP hbmp;
RenderedBitmap *rendered = NULL;
if (bmp->GetHBITMAP((ARGB)Color::White, &hbmp) == Ok)
rendered = new RenderedBitmap(hbmp, SizeI(bmp->GetWidth(), bmp->GetHeight()));
delete bmp;
return rendered;
}
示例10: InitIconImage
void CBalloonTip::InitIconImage()
{
HICON hIcon = LoadIcon(CPaintManagerUI::GetResourceDll(),MAKEINTRESOURCE(m_nIcon));
if (hIcon)
{
ICONINFO icInfo = { 0 };
if (::GetIconInfo(hIcon, &icInfo))
{
BITMAP bitmap;
GetObject(icInfo.hbmColor, sizeof(BITMAP), &bitmap);
Bitmap* pBitmap = NULL;
Bitmap* pWrapBitmap = NULL;
if (bitmap.bmBitsPixel != 32)
{
pBitmap = Bitmap::FromHICON(hIcon);
}
else
{
pWrapBitmap = Bitmap::FromHBITMAP(icInfo.hbmColor, NULL);
BitmapData bitmapData;
Rect rcImage(0,0, pWrapBitmap->GetWidth(), pWrapBitmap->GetHeight());
pWrapBitmap->LockBits(&rcImage, ImageLockModeRead, pWrapBitmap->GetPixelFormat(), &bitmapData);
pBitmap = new Bitmap(bitmapData.Width, bitmapData.Height, bitmapData.Stride, PixelFormat32bppARGB, (BYTE*)bitmapData.Scan0);
pWrapBitmap->UnlockBits(&bitmapData);
}
//lpIconImage = pBitmap->Clone(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight(), PixelFormat32bppARGB);
HBITMAP hBit ;
pBitmap->GetHBITMAP(ARGB(0,0,0,0),&hBit);
m_pPM->AddImage(_T("BalloonIcon"),hBit,pBitmap->GetWidth(),pBitmap->GetHeight(),TRUE);
DeleteObject(icInfo.hbmColor);
DeleteObject(icInfo.hbmMask);
}
DeleteObject(hIcon);
}
}
示例11: LoadRenderedBitmap
static RenderedBitmap* LoadRenderedBitmap(const WCHAR* filePath) {
OwnedData data(file::ReadFile(filePath));
if (!data.data) {
return nullptr;
}
Bitmap* bmp = BitmapFromData(data.data, data.size);
if (!bmp) {
return nullptr;
}
HBITMAP hbmp;
RenderedBitmap* rendered = nullptr;
if (bmp->GetHBITMAP((ARGB)Color::White, &hbmp) == Ok) {
rendered = new RenderedBitmap(hbmp, SizeI(bmp->GetWidth(), bmp->GetHeight()));
}
delete bmp;
return rendered;
}
示例12: ApplyBitmap
Bool AlphaWindow::ApplyBitmap( Bitmap& bitmap ) {
Bool success = false;
SizeF bitmapSize;
bitmap.GetPhysicalDimension( &bitmapSize );
// Size and move our window
FitsLiberator::Rectangle windowBounds( 0, 0, (Int)bitmapSize.Width, (Int)bitmapSize.Height );
setBounds( windowBounds );
Center();
windowBounds = getBounds();
HDC screenDC = ::GetDC( NULL );
HDC memDC = ::CreateCompatibleDC( screenDC );
HBITMAP hBitmap = NULL;
HBITMAP hOldBitmap = NULL;
if( Ok == bitmap.GetHBITMAP( Gdiplus::Color(0), &hBitmap ) ) {
hOldBitmap = (HBITMAP)::SelectObject( memDC, hBitmap );
SIZE newSize = { (Int)bitmapSize.Width, (Int)bitmapSize.Height };
POINT sourceLocation = { 0, 0 };
POINT newLocation = { windowBounds.left, windowBounds.top };
BLENDFUNCTION blend;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = AC_SRC_ALPHA;
::UpdateLayeredWindow( hWnd, screenDC, &newLocation, &newSize, memDC, &sourceLocation, 0, &blend, ULW_ALPHA );
success = true;
}
::ReleaseDC( NULL, screenDC );
if( hBitmap != NULL ) {
::SelectObject( memDC, hOldBitmap );
::DeleteObject( hBitmap );
}
::DeleteDC( memDC );
return success;
}
示例13: MakeMovieWithImages
//.........这里部分代码省略.........
CString profileFilename;
profileFilename.Format("%sHD_Recording.xml" , ((CProteinVistaApp *)AfxGetApp())->m_strBaseResPath );
// Reading buffer
CFile* pFile = new CFile(profileFilename, CFile::modeRead );
if ( pFile->m_hFile != CFile::hFileNull )
{
long fileLen = pFile->GetLength()*sizeof(wchar_t) * 2;
wchar_t * buffer = new wchar_t [fileLen];
wchar_t * bufferProfile = new wchar_t [fileLen];
ZeroMemory(buffer, fileLen);
ZeroMemory(bufferProfile, fileLen);
long nRead = pFile->Read( buffer, fileLen );
pFile->Close();
swprintf(bufferProfile, buffer, bitmapWidth, bitmapHeight,
bitmapWidth, bitmapHeight,
bitmapWidth, bitmapHeight );
if(FAILED(pProfileManager->LoadProfileByData(bufferProfile, &pProfile)))
{
AfxMessageBox(_T("Unable to Load Data Profile"));
return E_FAIL;
}
delete [] buffer;
delete [] bufferProfile;
SAFE_RELEASE(pProfileManager);
SAFE_DELETE(pFile);
}
else
{
SAFE_RELEASE(pProfileManager);
AfxMessageBox(_T("Cannot find HD_Recording.xml"));
return E_FAIL;
}
}
//
// movieFilename 을 지운다.
TCHAR drive[MAX_PATH];
TCHAR dir[MAX_PATH];
TCHAR fname[MAX_PATH];
TCHAR ext[MAX_PATH];
_splitpath(movieFilename, drive, dir, fname, ext );
CString strMovieFilename;
if ( drive[0] != NULL && dir[0] != NULL )
{
strMovieFilename = CString(movieFilename);
}
else
{
strMovieFilename.Format(_T("%s%s%s") , ((CProteinVistaApp *)AfxGetApp())->m_strBaseScriptMovie, fname, ext );
}
DeleteFile(strMovieFilename);
//
CwmvFile wmvFile (strMovieFilename, pProfile, fps);
if ( wmvFile.GetLastErrorMessage() != CString (_T("Method Succeeded") ) )
{
CString strText;
strText.Format( "%s: Cannot open %s", wmvFile.GetLastErrorMessage(), movieFilename );
AfxMessageBox ( strText );
return E_FAIL;
}
for ( int i = 0 ; i < strArrayFilename.GetSize(); i++ )
{
USES_CONVERSION;
Bitmap * bitmap = Bitmap::FromFile(A2W(strArrayFilename[i]));
Color colorBackground;
HBITMAP hBitmap;
bitmap->GetHBITMAP(colorBackground,&hBitmap);
long frames = arrayFrame[i];
for ( int j = 0 ; j < frames ; j++ )
{
hr = wmvFile.AppendNewFrame(hBitmap);
}
if ( FAILED(hr) )
{
CString strText;
strText.Format( "Movie Making Error: %s, %s", wmvFile.GetLastErrorMessage(), strArrayFilename[i] );
AfxMessageBox ( strText );
delete bitmap;
return E_FAIL;
}
delete bitmap;
}
return S_OK;
}
示例14: LoadBitmapFromMem
// 读取图片(从内存中加载)
BOOL LoadBitmapFromMem(BYTE* pByte, DWORD dwSize, CBitmap &bitmap, CSize &size)
{
// 根据文件大小分配HGLOBAL内存
HGLOBAL hGlobal = GlobalAlloc( GMEM_MOVEABLE | GMEM_NODISCARD, dwSize );
if ( !hGlobal )
{
TRACE( _T( "Load (file): Error allocating memory\n" ) );
return FALSE;
};
char *pData = reinterpret_cast<char*>(GlobalLock(hGlobal));
if ( !pData )
{
TRACE( _T( "Load (file): Error locking memory\n" ) );
GlobalFree( hGlobal );
return FALSE;
};
// 将文件内容读到HGLOBAL内存中
memcpy(pData, pByte, dwSize);
GlobalUnlock( hGlobal );
// 利用hGlobal内存中的数据创建stream
IStream *pStream = NULL;
if ( CreateStreamOnHGlobal( hGlobal, TRUE, &pStream ) != S_OK )
{
return FALSE;
}
Bitmap* pBitmap = Gdiplus::Bitmap::FromStream(pStream);
// 要加上这一句,否则由GlobalAlloc得来的hGlobal内存没有被释放,导致内存泄露,由于
// CreateStreamOnHGlobal第二个参数被设置为TRUE,所以调用pStream->Release()会自动
// 将hGlobal内存(参见msdn对CreateStreamOnHGlobal的说明)
pStream->Release();
HBITMAP hBitmap = NULL;
Status status = pBitmap->GetLastStatus();
if(Ok == status)
{
status = pBitmap->GetHBITMAP(Color(0,0,0), &hBitmap);
delete pBitmap;
if(Ok == status)
{
if(bitmap.m_hObject != NULL)
{
bitmap.Detach();
}
bitmap.Attach(hBitmap);
BITMAP bmInfo;
::GetObject( bitmap.m_hObject, sizeof(BITMAP), &bmInfo );
size.cx = bmInfo.bmWidth;
size.cy = bmInfo.bmHeight;
return TRUE;
}
}
return FALSE;
}
示例15: GetThumbnail
//.........这里部分代码省略.........
if (left + bmp_width >= CX)
{
gfx.DrawImage(&text_bitmap, X, (int)textheight, -left, 0, CX, bmp_height, UnitPixel);
}
else
{
gfx.DrawImage(&text_bitmap, X, (int)textheight, -left, 0, bmp_width + left,
bmp_height, UnitPixel);
gfx.DrawImage(&text_bitmap, X + text_space + 2 + bmp_width + left, (int)textheight, 0, 0,
-left, bmp_height, UnitPixel);
}
}
else
{
// Draw non-scrolling text
if (current_settings.center)
{
// Center text
int newleft = X + ((CX / 2) - (text_bitmap.GetWidth() / 2));
gfx.DrawImage(&text_bitmap, newleft, (int)textheight, 0, 0, text_bitmap.GetWidth(), text_bitmap.GetHeight(), UnitPixel);
}
else
{
gfx.DrawImage(&text_bitmap, X, (int)textheight, 0, 0, text_bitmap.GetWidth(), text_bitmap.GetHeight(), UnitPixel);
}
m_textpositions[text_index] = 2; // Nr. pixels text jumps on each step when scrolling
}
gfx.ResetClip();
textheight += text_bitmap.GetHeight();
}
if (m_textpause > 0)
{
--m_textpause;
}
if (!m_Settings.Shrinkframe)
textheight = height-2;
if (m_Settings.Thumbnailpb)
textheight += 25;
if (textheight > height-2)
textheight = height-2;
}
// Draw progressbar
if (m_Settings.Thumbnailpb && m_Settings.play_total > 0)// && m_Settings.play_current >0)
{
gfx.SetSmoothingMode(SmoothingModeAntiAlias);
int Y = canvas->GetHeight()-10;
if (m_Settings.Shrinkframe)
{
Y = textheight - 10;
}
Pen p1(Color::White, 1);
Pen p2(Color::MakeARGB(80, 0, 0, 0), 1);
SolidBrush b1(Color::MakeARGB(50, 0, 0, 0));
SolidBrush b2(Color::MakeARGB(220, 255, 255, 255));
RectF R1(44, (REAL)Y, 10, 9);
RectF R2((REAL)width - 56, (REAL)Y, 10, 9);
gfx.FillRectangle(&b1, 46, Y, width-94, 9);
gfx.DrawLine(&p2, 46, Y+2, 46, Y+6);
gfx.DrawLine(&p2, width-48, Y+2, width-48, Y+6);
gfx.DrawArc(&p1, R1, -90.0f, -180.0f);
gfx.DrawArc(&p1, R2, 90.0f, -180.0f);
gfx.DrawLine(&p1, 48, Y, width-49, Y);
gfx.DrawLine(&p1, 48, Y+9, width-49, Y+9);
gfx.SetSmoothingMode(SmoothingModeDefault);
gfx.FillRectangle(&b2, 48, Y+3, (m_Settings.play_current*(width-96))/m_Settings.play_total, 4);
}
// finalize / garbage
HBITMAP retbmp;
if (!m_Settings.Shrinkframe)
{
canvas->GetHBITMAP(NULL, &retbmp);
}
else
{
Bitmap *shrink = canvas->Clone(0, 0, (int)width,
textheight > m_iconheight ? (int)textheight : (int)m_iconheight, PixelFormat32bppPARGB);
shrink->GetHBITMAP(NULL, &retbmp);
delete shrink;
}
delete canvas;
return retbmp;
}