首页 > 其他分享 >关于LoadImage

关于LoadImage

时间:2023-01-04 14:39:22浏览次数:42  
标签:function resource color image LR 关于 LoadImage parameter


要写一个位图播放软件demo,用定时器每隔100ms从硬盘中读取一副位图然后显示,所以用API LoadImage从硬盘中读取位图,函数调用如下

HBITMAP bmp = (HBITMAP)LoadImage(NULL, strFileName.GetBuffer(), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE)

结果定时器计数到50~60次时,动画便停止。

本来以为是定时器被堵死,无法响应中断,然后尝试将文件放到内存中直接显示,结果问题还是存在。

然后单步调试跟踪发现是LoadImage在执行了50~60次以后载入位图出错,bmp地址为0x00000000,参阅MSDN

LoadImage
<script src="langref.js"></script>
The LoadImage function loads an icon, cursor, animated cursor, or bitmap.

HANDLE LoadImage(
HINSTANCEhinst,


// handle to instance
LPCTSTRlpszName,


// image to load
UINTuType,


// image type
intcxDesired,


// desired width
intcyDesired,


// desired height
UINTfuLoad


// load options
);

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] Specifies the image to load. If the hinst parameter is non-NULL and the

fuLoad parameter omits LR_LOADFROMFILE,

lpszName specifies the image resource in the

hinst module. If the image resource is to be loaded by name, the

lpszName parameter is a pointer to a null-terminated string that contains the name of the image resource. If the image resource is to be loaded by ordinal, use the

MAKEINTRESOURCE macro to convert the image ordinal into a form that can be passed to the

LoadImage function.

If the hinst parameter is NULL and the fuLoad parameter omits the LR_LOADFROMFILE value, the lpszName specifies 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

To pass these constants to the LoadImage function, use the MAKEINTRESOURCE macro. For example, to load the OCR_NORMAL cursor, pass MAKEINTRESOURCE (OCR_NORMAL) as the lpszName parameter and NULL as the hinst parameter.

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

uType

Value

Meaning

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 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

[in] 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

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 3-D 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

 

Do not use this option if you are loading a bitmap with a color depth greater than 8bpp.

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.

Do not use this option if you are loading a bitmap with a color depth greater than 8bpp.

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.

When you use this flag, the system will destroy the resource when it is no longer needed.

Do not use LR_SHARED for images that have non-standard sizes, that may change after loading, or that are loaded from a file.

When loading a system icon or cursor, you must use LR_SHARED or the function will fail to load the resource.

Windows 95/98/Me: 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.

当加载OEM位图,并且fuLoad为LR_LOADFROMFILE,hinst可以等于NULL,所以将函数调用修改为

HBITMAP bmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(), strFileName.GetBuffer(), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);

一切OK。但是问题是能够正常运行一段时间,然后动画终止?

 

标签:function,resource,color,image,LR,关于,LoadImage,parameter
From: https://blog.51cto.com/u_15929756/5988596

相关文章

  • 关于cef的几个知识点
    执行JS(JavaScript)代码,无返回值browser.GetBrowser().MainFrame.ExecuteJavaScriptAsync("document.getElementById('testid').click();");browser.GetBrowser().Mai......
  • cmake关于相对路径的一些参数
    项目文件结构  cmake_minimum_required(VERSION3.15)project(AddTest)message("CMAKE_CURRENT_BINARY_DIR:"${CMAKE_CURRENT_BINARY_DIR})message("CMAKE_CU......
  • 关于 safari浏览器 不支持new Date 显示NaN的问题记录
    知识点:newDate问题: safari浏览器 显示NaN因为 JS中要求Date类型转换的原始数据格式是yyyy/mm/dd之类的,所以横岗-要替换掉才可以今天同事来问,我一看果然啊,mac版高......
  • 关于数据排序问题使用sort排序
    字母和数字一起排序数字的排序是优先于字母的,   varfruits=["Banana","Orange","Apple","Mango",1,'1',22,1,0,'33'];fruits.sort();//0,1,1,1,......
  • 关于想把console.log的数据复制出来
    打印了一堆console.log,但是想把它拿出来看,网上找了找果然有方法1.  鼠标右键打印的数据,有一个存储对象作为全局变量点击以后会出来一个temp1  最后只需要copy(t......
  • 关于Unreal使用Dedicate Server时的一些研究
    下面的博客链接内容如下:直接点击即可他说的UE4自带的服务器只能用于Development和debugment需要留意一下,不能用于商用版本,说这个性能很低,这个需要我留意一下 这是论......
  • [答疑]关于公众号答题比赛第5轮第1题的解析
    flen2018-11-2721:09第一个题目谁能解释一下潘加宇:本轮共3道题,很多人栽在了第1题,看到选项D是个用例图,就选了D。题目如下:1、以下属于描述"电视机"需求的是:A)B)C)D)我们先来......
  • matlab关于阶梯图和图窗操作
    1阶梯信号绘制Matlab中绘制阶梯图函数:stairsx=[3033374037333027232023273030]';StepNum=length(x);t=[0:600:(StepNum-1)*600]';阶梯信号展示:......
  • 关于uniapp多层弹窗click事件点击唤起textarea键盘的问题
    原因由于textarea在原生组件中优先级高,导致click事件会优先触发textarea的点击中间遇到的问题由于使用cover-view将组件优先级实现了覆盖textarea的优先级,但是弹窗中的......
  • NASA关于MSL(火星科学实验室,好奇号)的UML状态图自动编码讲座
    NASA关于MSL(火星科学实验室,好奇号)的UML状态图自动编码讲座火星科学实验室(MarsScienceLaboratory,MSL)好奇号(Curiosity)是美国国家航空航天局(NASA)的探测车计划,探测器已......