事情是这样的,本人在编译3D游戏编程大师技巧中的程序是遇到了一个关于位图读取函数int Load_Bitmap_File的lseek问题。

我使用以下位图读取函数读取位图事报错如下:

int Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename)
{
// this function opens a bitmap file and loads the data into bitmap int file_handle, // the file handle
index; // looping index UCHAR *temp_buffer = NULL; // used to convert 24 bit images to 16 bit
OFSTRUCT file_data; // the file data information // open the file if it exists
if ((file_handle = OpenFile(filename,&file_data,OF_READ))==-)
return(); // now load the bitmap file header
_lread(file_handle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER)); // test if this is a bitmap file
if (bitmap->bitmapfileheader.bfType!=BITMAP_ID)
{
// close the file
_lclose(file_handle); // return error
return();
} // end if // now we know this is a bitmap, so read in all the sections // first the bitmap infoheader // now load the bitmap file header
_lread(file_handle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER)); // now load the color palette if there is one
if (bitmap->bitmapinfoheader.biBitCount == )
{
_lread(file_handle, &bitmap->palette,MAX_COLORS_PALETTE*sizeof(PALETTEENTRY)); // now set all the flags in the palette correctly and fix the reversed
// BGR RGBQUAD data format
for (index=; index < MAX_COLORS_PALETTE; index++)
{
// reverse the red and green fields
int temp_color = bitmap->palette[index].peRed;
bitmap->palette[index].peRed = bitmap->palette[index].peBlue;
bitmap->palette[index].peBlue = temp_color; // always set the flags word to this
bitmap->palette[index].peFlags = PC_NOCOLLAPSE;
} // end for index } // end if // finally the image data itself
_lseek(file_handle,-(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END); // now read in the image
if (bitmap->bitmapinfoheader.biBitCount== || bitmap->bitmapinfoheader.biBitCount==)
{
// delete the last image if there was one
if (bitmap->buffer)
free(bitmap->buffer); // allocate the memory for the image
if (!(bitmap->buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
{
// close the file
_lclose(file_handle); // return error
return();
} // end if // now read it in
_lread(file_handle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage); } // end if
else
if (bitmap->bitmapinfoheader.biBitCount==)
{
// allocate temporary buffer to load 24 bit image
if (!(temp_buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
{
// close the file
_lclose(file_handle); // return error
return();
} // end if // allocate final 16 bit storage buffer
if (!(bitmap->buffer=(UCHAR *)malloc(*bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight)))
{
// close the file
_lclose(file_handle); // release working buffer
free(temp_buffer); // return error
return();
} // end if // now read the file in
_lread(file_handle,temp_buffer,bitmap->bitmapinfoheader.biSizeImage); // now convert each 24 bit RGB value into a 16 bit value
for (index=; index < bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight; index++)
{
// build up 16 bit color word
USHORT color; // build pixel based on format of directdraw surface
if (dd_pixel_format==DD_PIXEL_FORMAT555)
{
// extract RGB components (in BGR order), note the scaling
UCHAR blue = (temp_buffer[index* + ] >> ),
green = (temp_buffer[index* + ] >> ),
red = (temp_buffer[index* + ] >> );
// use the 555 macro
color = _RGB16BIT555(red,green,blue);
} // end if 555
else
if (dd_pixel_format==DD_PIXEL_FORMAT565)
{
// extract RGB components (in BGR order), note the scaling
UCHAR blue = (temp_buffer[index* + ] >> ),
green = (temp_buffer[index* + ] >> ),
red = (temp_buffer[index* + ] >> ); // use the 565 macro
color = _RGB16BIT565(red,green,blue); } // end if 565 // write color to buffer
((USHORT *)bitmap->buffer)[index] = color; } // end for index // finally write out the correct number of bits
bitmap->bitmapinfoheader.biBitCount=; // release working buffer
free(temp_buffer); } // end if 24 bit
else
{
// serious problem
return(); } // end else #if 0
// write the file info out
printf("\nfilename:%s \nsize=%d \nwidth=%d \nheight=%d \nbitsperpixel=%d \ncolors=%d \nimpcolors=%d",
filename,
bitmap->bitmapinfoheader.biSizeImage,
bitmap->bitmapinfoheader.biWidth,
bitmap->bitmapinfoheader.biHeight,
bitmap->bitmapinfoheader.biBitCount,
bitmap->bitmapinfoheader.biClrUsed,
bitmap->bitmapinfoheader.biClrImportant);
#endif // close the file
_lclose(file_handle); // flip the bitmap
Flip_Bitmap(bitmap->buffer,
bitmap->bitmapinfoheader.biWidth*(bitmap->bitmapinfoheader.biBitCount/),
bitmap->bitmapinfoheader.biHeight); // return success
return(); } // end Load_Bitmap_File

编译运行会产生以下问题

查lseek函数介绍也没有发现问题。

http://c.biancheng.net/cpp/html/236.html

然后就查找_lseek()函数在新版本有什么变化。没有查到

http://www.educity.cn/wenda/493024.html

去google搜索到许多人遇到问题,但是没有解决办法。

http://www.debugease.com/vc/2006166.html

还搜到一个人说是因为OS是vista也没说具体解决办法。

https://social.msdn.microsoft.com/Forums/vstudio/en-US/2dde18b1-fe36-4679-8ed2-ee61beee4af3/moves-a-file-pointer-to-the-specified-location?forum=vsdebug

最终在百度知道找到一个答案,就说了一句话把lseek()函数注释掉。。我开始怎么没想到。

解决办法:将

_lseek(file_handle,-(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);

注释掉,我也不知道会产生什么影响,但是错误解决了。暂时先这样解决吧

关于位图读取函数int Load_Bitmap_File的lseek问题。的更多相关文章

  1. 写一个函数int get(),这个函数运行一次可以从V[N]里随机取出一个数,而这个数必须是符合1/N平均分布的

    题目:有一个函数int getNum(),每运行一次可以从一个数组V[N]里面取出一个数,N未知,当数取完的时候,函数返回NULL.现在要求写一个函数int get(),这个函数运行一次可以从V[N] ...

  2. error LNK2019: 无法解析的外部符号 WinMain,该符号在函数 "int __cdecl invoke_main(void)”中被引用

    一,问题描述 MSVCRTD.lib(exe_winmain.obj) : error LNK2019: 无法解析的外部符号 WinMain,该符号在函数 "int __cdecl invo ...

  3. 关于图像读取函数imread()的一点使用经验,注意默认参数的赋值

    读入数字图像到数组,用CNN进行训练,发现关于图像读取的一个问题. 问题描述:读取灰度数字图像,在验证时发现存在错误,从图像到数组中的值不完全一样? main code as follows: int ...

  4. Oracle 优化——位图、函数等索引介绍

    一.位图索引 我将使用一个例子,来描述位图索引的存储,并分析它的优点. Table :Loans 放贷信息 ID userId 行业投向 币种 证件类型 还本付息方式 状态 1 1 农业 人民币 身份 ...

  5. 基础 - 字符读取函数scanf、getchar、gets、cin(清空缓存区解决单字符回车问题)

    0x01 scanf.getchar.cin读取单字符: 如下: //scanf读取字符 回车问题 void Sub_1_1() { char v1,v2; scanf("%c", ...

  6. 题目1029:魔咒词典(map使用以及字符串读取函数总结)

    题目链接:http://ac.jobdu.com/problem.php?pid=1029 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus // // ...

  7. python学习笔记~INI、REG文件读取函数(自动修复)

    引入configparser,直接read整个INI文件,再调用get即可.但需要注意的是,如果INI文件本身不太规范,就会报各种错,而这又常常不可避免的.本文自定义函数通过try...except. ...

  8. 图像读取函数cv::imread()的几种使用方式

    string imgpath = "C:\Users\Y\Pictures\miao.jpg"; OpenCV的imread()函数不支持单右斜线形式的路径,即不支持上述形式的路径 ...

  9. mfc 位图本地存储 本地位图读取显示

    一.读取CImage //在绘图函数中直接使用参数pDC,无需定义 CDC* pDC = GetDC(): //读去位图路径,根据实际情况修改 CString loatImagePath = TEXT ...

随机推荐

  1. Android手机无法访问百度空间的解决办法

    本文网址:http://www.cnblogs.com/tunnel213/p/4301165.html 现象: 百度“JavaScript函数高级”后找到一篇文章,百度空间的,无法查看: 配置: 三 ...

  2. spring aop 声明式事务管理

    一.声明式事务管理的概括 声明式事务(declarative transaction management)是Spring提供的对程序事务管理的方式之一. Spring的声明式事务顾名思义就是采用声明 ...

  3. box-shadow

    box-shadow:a b c d e; a-水平位置,相对于盒子本身在水平方向的正偏移距离: b-垂直位置: c-模糊距离: d-阴影尺寸,从盒子的边框开始算起的阴影的宽度: e-阴影颜色: f- ...

  4. js和jquery获取图片真实的宽度和高度

    1.什么时候需要获取图片真实的宽度和高度 在做pc网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式! 另外一种就是在手机页面上,在新闻页插入的图片往 ...

  5. JS截取字符串常用方法详细整理

    使用 substring()或者slice() 函数:split() 功能:使用一个指定的分隔符把一个字符串分割存储到数组 例子: str="jpg|bmp|gif|ico|png" ...

  6. Docker简明教程

    Docker简明教程 [编者的话]使用Docker来写代码更高效并能有效提升自己的技能.Docker能打包你的开发环境,消除包的依赖冲突,并通过集装箱式的应用来减少开发时间和学习时间. Docker作 ...

  7. PKU1004

    求平均数,就是要注意浮点数精度保持,由于浮点数在计算机内部的表示不同,会导致精度不好,这里由于输入的限制,计算的时候采用了整数,防止精度丢失 // 1004.cpp : 定义控制台应用程序的入口点. ...

  8. KBEngine 学习笔记

    最近开始学习 KBE 扩展技能点>_<!所以建一个随笔记录一下遇到的小问题: 问题1 :DBMgr找不到LibMysql32.dll 解决:VS 中KBE源码 默认的是Win32 ,Win ...

  9. Memcache所有方法及参数详解

    memcache函数所有的方法列表如下: 参考http://www.php.net/manual/zh/function.Memcache-add.php Memcache::add - 添加一个值, ...

  10. Teleport Ultra 下载网页修复

    1 三个基本正则替换 tppabs="h[^"]*"/\*tpa=h[^"]*/javascript:if\(confirm\('h[^"]*[Ult ...