用LoadImage() 方法加载bmp图像有大小限制吗?

wjqymx 2007-11-06 09:11:15
请教:

使用LoadImage()方法从文件加载bmp格式图像,有大小限制吗? 我加载了一个几百k的图像没有问题,但是加载一个32M的bmp图像文件,返回值为NULL,能否解决加载大图像问题?
...全文
2326 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
vtkzhang 2007-11-07
  • 打赏
  • 举报
回复
可以尝试用小bmp文件打开,然后逐步增大看看到何时打开失败了,然后在google上搜索此尺寸是否为临界值,一般在msdn上无解时只能这么作。
element_cn 2007-11-07
  • 打赏
  • 举报
回复
CXImage

你可以先创建一个,看行不
凤矶 2007-11-07
  • 打赏
  • 举报
回复
应该与动态分配内存的大小限制一致。
pptor 2007-11-07
  • 打赏
  • 举报
回复
哈哈 同意楼上的做法
wjqymx 2007-11-06
  • 打赏
  • 举报
回复
谢谢楼上的兄弟,我看过msdn的解释,可是没有说明有大小限制呀?
Tommy_Yu2 2007-11-06
  • 打赏
  • 举报
回复
The LoadImage function loads an icon, cursor, or bitmap.

HANDLE LoadImage(
HINSTANCE hinst, // handle of the instance containing the image
LPCTSTR lpszName, // name or identifier of image
UINT uType, // type of image
int cxDesired, // desired width
int cyDesired, // desired height
UINT fuLoad // load flags
);

Parameters
hinst
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
Handle to 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 Meaning
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
Specifies the type of image to be loaded. This parameter can be one of the following values: Value Meaning
IMAGE_BITMAP Loads a bitmap.
IMAGE_CURSOR Loads a cursor.
IMAGE_ICON Loads an icon.


cxDesired
Specifies the width, in pixels, of the icon or cursor. If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CXICON or SM_CXCURSOR system metric value to set the width. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource width.
cyDesired
Specifies the height, in pixels, of the icon or cursor. If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CYICON or SM_CYCURSOR system metric value to set the height. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource height.
fuLoad
Specifies a combination of the following values: Value Meaning
LR_DEFAULTCOLOR The default flag; it does nothing. All it means is "not LR_MONOCHROME".
LR_CREATEDIBSECTION When the uType parameter specifies IMAGE_BITMAP, causes the function to return a DIB section bitmap rather than a compatible bitmap. This flag is useful for loading a bitmap without mapping it to the colors of the display device.
LR_DEFAULTSIZE 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 this flag is not specified and cxDesired and cyDesired are set to zero, the function uses the actual resource size. If the resource contains multiple images, the function uses the size of the first image.
LR_LOADFROMFILE Loads the image from the file specified by the lpszName parameter. If this flag is not specified, lpszName is the name of the resource.
LR_LOADMAP3DCOLORS Searches the color table for the image and replaces the following shades of gray with the corresponding 3D color:

Color Replaced with
Dk Gray,
RGB(128,128,128) COLOR_3DSHADOW
Gray,
RGB(192,192,192) COLOR_3DFACE
Lt Gray,
RGB(223,223,223) COLOR_3DLIGHT

LR_LOADTRANSPARENT Retrieves the color value of the first pixel in the image and replaces the corresponding entry in the color table with the default window color (COLOR_WINDOW). All pixels in the image that use that entry become the default window color. This value applies only to images that have corresponding color tables.
If fuLoad includes both the LR_LOADTRANSPARENT and LR_LOADMAP3DCOLORS values, LRLOADTRANSPARENT takes precedence. However, the color table entry is replaced with COLOR_3DFACE rather than COLOR_WINDOW.

LR_MONOCHROME Loads the image in black and white.
LR_SHARED Shares the image handle if the image is loaded multiple times. If LR_SHARED is not set, a second call to LoadImage for the same resource will load the image again and return a different handle.
Do not use LR_SHARED for images that have non-standard sizes, that may change after loading, or that are loaded from a file.

Windows 95 and Windows 98: The function finds the first image with the requested resource name in the cache, regardless of the size requested.

LR_VGACOLOR Uses true VGA colors.


Return Values
If the function succeeds, the return value is the handle of the newly loaded image.

If the function fails, the return value is NULL. To get extended error information, callGetLastError
VC PICTURE控件的使用,如何加载背景图片2009年04月19日 星期日 15:02vc picture控件的分类总结: (一) 非动态显示图片(即图片先通过资源管理器载入,有一个固定ID) (二) 动态载入图片(即只需要在程序中指定图片的路径即可载入) 为方便说明,我们已经建好一个基于对话框的工程,名为Ttest. 对话框类为CTestDlg (一) vc picture控件非动态载入图片. 方法1.先从最简单的开始,用picture 控件来实现. 步骤: 先在资源里Import一张图片,ID为IDB_BITMAP2 然后在对话框上添加一个picture控件,右键点击打开属性, 将type下拉框选择BITMAP,紧跟着下面就出现一个Image下拉框, 拉开就会看到所有已经载入好的图片, 选择你要的图片.运行程序即可看到. 方法2vc picture控件.通过背景图 同样如上,先载入一张图片,ID为IDB_BITMAP2 TestDlg.h中 CBrush m_brBk;//在public中定义 TestDlg.cpp中 在初始化函数OnInitDialog()中加入: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP2); m_brBk.CreatePatternBrush(&bmp); bmp.DeleteObject(); return TRUE; // return TRUE unless you set the focus to a control } 在打开类向导,找到WM_CTLCOLOR消息,重载得对应函数OnCtlColor(),添加如下: HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd == this) { return m_brBk; } return hbr; } (二) vc picture控件动态载入图片. 方法3 图像控件(本例用KoDak 图像编辑控件) 1. 首先应该保证系统中有这个控件。注意,它不能单独使用,必须和其他几个控件(特别是Imgcmn.dll)一同使用。如果没有,从别的机器上copy过来即可。这几个文件是Imgadmin.ocx,Imgcmn.dll,Imgedit.ocx,Imgscan.ocx,Imgshl.dll,Imgthumb.ocx,Imgutil.dll,把它们copy到windows\system目录下,然后用regsvr32.exe将它们分别注册。 2. 打开工程,进入资源管理器,在对话框上单击右键,单击Insert Activex control… 选择Kodak图象编辑控件,大小任意。 3. 在对话框上选中该控件,为其添加变量:m_ctrlPicture。。 4. 在BOOL CTestDlg::OnInitDialog()添加如下: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); m_ctrlPicture.SetImage("aa.jpg"); //保证图像在工程目录下,也可以写绝对路径 m_ctrlPicture.Display(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } 编译运行就OK了,此种方法的好处就是可能针对多种图像格式. 方法4 vc picture控件通过CBitmap,HBITMAP,直接用OnPaint()绘制 首先在CTestDlg类中声明一个变量: CBitmap m_bmp; 然后我们在对话框中加入一个picture 标签,名为IDC_STATIC1 然后: BOOL CDisplayPic::OnInitDialog() { CDialog::OnInitDialog(); if( m_bmp.m_hObject != NULL )//判断 m_bmp.DeleteObject(); /////////载入图片 HBITMAP hbmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), "c:\\aaa.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE); if( hbmp == NULL ) return FALSE; ///////////////////////该断程序用来取得加载BMP的信息//////////////////////// m_bmp.Attach( hbmp ); DIBSECTION ds; BITMAPINFOHEADER &bminfo = ds.dsBmih; m_bmp.GetObject( sizeof(ds), &ds ); int cx=bminfo.biWidth; //得到图像宽度 int cy=bminfo.biHeight; //得到图像高度 /////////////////// //////////////////////////////// /////////////得到了图像的宽度和高度后,我们就可以对图像大小进行适应,即调整控件的大小,让它正好显示一张图片/////////////////////////// CRect rect; GetDlgItem(IDC_STATIC1)->GetWindowRect(&rect); ScreenToClient(&rect); GetDlgItem(IDC_STATIC1)->MoveWindow(rect.left,rect.top,cx,cy,true);//调整大小 return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } 图片加载成功了,标签大小也适应了,下面就是绘制绘制图像了,打开类向导,重载WM_PAINT消息 void CDisplayPic::OnPaint() { //////////////以下三种情况任选一种会是不同效果(只能一种存在)/////////// //CPaintDC dc(this); //若用此句,得到的是对话框的DC,图片将被绘制在对话框上. CPaintDC dc(GetDlgItem(IDC_STATIC1)); //用此句,得到picture控件的DC,图像将被绘制在控件上 // CDC dc; // dc.m_hDC=::GetDC(NULL); //若用此两句,得到的是屏幕的DC,图片将被绘制在屏幕上/////////////////////////////////////////////////////// CRect rcclient; GetDlgItem(IDC_STATIC1)->GetClientRect(&rcclient); CDC memdc; memdc.CreateCompatibleDC(&dc); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dc, rcclient.Width(), rcclient.Height()); memdc.SelectObject( &bitmap ); CWnd::DefWindowProc(WM_PAINT, (WPARAM)memdc.m_hDC , 0); CDC maskdc; maskdc.CreateCompatibleDC(&dc); CBitmap maskbitmap; maskbitmap.CreateBitmap(rcclient.Width(), rcclient.Height(), 1, 1, NULL); maskdc.SelectObject( &maskbitmap ); maskdc.BitBlt( 0, 0, rcclient.Width(), rcclient.Height(), &memdc, rcclient.left, rcclient.top, SRCCOPY); CBrush brush; brush.CreatePatternBrush(&m_bmp); dc.FillRect(rcclient, &brush); dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(), &memdc, rcclient.left, rcclient.top,SRCPAINT); brush.DeleteObject(); // Do not call CDialog::OnPaint() for painting messages }

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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