怎么利用BMP文件名加载位图啊?

qiongzi 2003-05-30 11:24:47
VC里只有这样的用资源ID的方式么?
LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP));
有没有用图片文件名直接加载的函数啊?
各位给我写几句啊!
多谢 !!!
...全文
136 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
triggerd 2003-05-31
  • 打赏
  • 举报
回复
void CXXView::OnDraw(CDC* pDC)
{
HBITMAP bitmap=(HBITMAP)LoadImage(NULL,_T("filepath"),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE);
CBitmap bmp;BITMAP bm;
bmp.Attach(bitmap);
bmp.GetBitmap(&bm);
CDC dcImage;
if(!dcImage.CreateCompatibleDC(pDC))
return;
dcImage.SelectObject(&bmp);
pDC->BitBlt(0,0,bm.bmWidth,bm.bmHeight,&dcImage,0,0,SRCCOPY);
..
}
reval 2003-05-31
  • 打赏
  • 举报
回复
HRESULT MyClass::ShowPicture(CString lpstrFile,HWND hwnd,int nScrWidth,int nScrHeight)
{
HDC hDC_Temp=::GetDC(hwnd);

IPicture *pPic;
IStream *pStm;

BOOL bResult;

HANDLE hFile=NULL;
DWORD dwFileSize,dwByteRead;

//打开图形文件
hFile=CreateFile(lpstrFile,GENERIC_READ, FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

if (hFile!=INVALID_HANDLE_VALUE)
{
dwFileSize=GetFileSize(hFile,NULL);//获取文件字节数 if (dwFileSize==0xFFFFFFFF)
return E_FAIL;
}
else
{
return E_FAIL;
}

//分配存储空间
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
LPVOID pvData = NULL;

if (hGlobal == NULL)
return E_FAIL;

if ((pvData = GlobalLock(hGlobal)) == NULL)//锁定分配内存块 return E_FAIL;

ReadFile(hFile,pvData,dwFileSize,&dwByteRead,NULL);//把文件读入缓冲区
GlobalUnlock(hGlobal);

CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);

//装入图形文件
bResult=OleLoadPicture(pStm,dwFileSize,TRUE,IID_IPicture,(LPVOID*)&pPic);

if(FAILED(bResult))
return E_FAIL;

OLE_XSIZE_HIMETRIC hmWidth;//图片的真实宽度
OLE_YSIZE_HIMETRIC hmHeight;//图片的真实高度
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);


//将图形输出到屏幕
bResult=pPic->Render(hDC_Temp,0,0,nScrWidth,nScrHeight,0,hmHeight,hmWidth,-hmHeight,NULL);

pPic->Release();

CloseHandle(hFile);//关闭打开的文件
if (SUCCEEDED(bResult))
{
return S_OK;
}
else
{
return E_FAIL;
}
}

调用时:
...
ShowPicture(strFileName, m_photoctrl.GetSafeHwnd(), 88, 108);
...
shilong 2003-05-31
  • 打赏
  • 举报
回复
LoadImage
This function loads an icon, cursor, or bitmap.

HANDLE LoadImage(
HINSTANCE hinst,
| LPCTSTR lpszName,
UINT uType,
int cxDesired,
int cyDesired,
UINT fuLoad );
Parameters
hinst
[in] Handle to an instance of the module that contains the image to be loaded. To load an OEM image, set this parameter to zero.
lpszName
[in] Identifies the image to load. If the hinst parameter is non-NULL and the fuLoad parameter does not include LR_LOADFROMFILE, lpszName is a pointer to a null-terminated string that contains the name of the image resource in the hinst module.
If hinst is NULL and LR_LOADFROMFILE is not specified, the low-order word of this parameter must be the identifier of the OEM image to load. The OEM image identifiers are defined in Winuser.h and have the following prefixes:

Prefix Description
OBM_ OEM bitmaps
OIC_ OEM icons
OCR_ OEM cursors




If the fuLoad parameter includes the LR_LOADFROMFILE value, lpszName is the name of the file that contains the image.

uType
[in] Specifies the type of image to be loaded. This parameter can be one of the following values:
Value Description
IMAGE_BITMAP Loads a bitmap.
IMAGE_CURSOR Loads a cursor.
IMAGE_ICON Loads an icon.




cxDesired
[in] Specifies the width, in pixels, of the icon or cursor. If this parameter is zero, the function uses the SM_CXICON or SM_CXCURSOR system metric value to set the width. If uType is IMAGE_BITMAP, this parameter must be zero.
cyDesired
[in] Specifies the height, in pixels, of the icon or cursor. If this parameter is zero, the function uses the SM_CYICON or SM_CYCURSOR system metric value to set the height. If uType is IMAGE_BITMAP, this parameter must be zero.
fuLoad
[in] Set to zero.
Windows CE behaves as though the LR_DEFAULTCOLOR and LR_DEFAULTSIZE values are set. LR_DEFAULTCOLOR means “not monochrome.” LR_DEFAULTSIZE means that the system uses the width or height specified by the system metric values for cursors or icons if the cxDesired or cyDesired values are set to zero. If the resource contains multiple images, the function uses the size of the first image.

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧