您的位置:程序门 -> vc/mfc -> 图形处理/算法



内存映射文件问题--高分求助


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


内存映射文件问题--高分求助
发表于:2007-07-01 17:11:11 楼主
老师给我布置一个任务,做一个小软件,在显示图象的部分是这样要求的,打开一个从硬盘里打开一个*.bmp文件,然后显示.但是要用内存映射文件.
在打开位图文件我写了两个函数,一个是
handle   readdibfile(handle   hfile)就是把dib读入内存里,
一个是handle   loaddib(lpctstr   lpfilename)从文件中装载dib(它调用上面的函数)
代码如下:
handle   loaddib(lpctstr   lpfilename)  
{  
        handle                 hdib;  
        handle             hfile;  
 
        //   set   the   cursor   to   a   hourglass,   in   case   the   loading   operation  
        //   takes   more   than   a   sec,   the   user   will   know   what 's   going   on.  
 
        setcursor(loadcursor(null,   idc_wait));  
 
        if   ((hfile   =   createfile(lpfilename,   generic_read,   file_share_read,   null,  
                        open_existing,   file_attribute_normal   ¦   file_flag_sequential_scan,  
                        null))   !=   invalid_handle_value)  
        {  
                hdib   =   readdibfile(hfile);  
                closehandle(hfile);  
                setcursor(loadcursor(null,   idc_arrow));  
                return   hdib;  
        }  
        else  
        {  
                setcursor(loadcursor(null,   idc_arrow));  
                return   null;  
        }  
}  
然后在cprcdoc中重载bool   cshowdibdoc::onopendocument(lpctstr   lpszpathname)  
{
if   (!cdocument::onopendocument(lpszpathname))
return   false;

m_hdib   =   loaddib(lpszpathname);
if   (m_hdib   ==   null)
{
//   may   not   be   dib   format
return   false;
}
setpathname(lpszpathname);
setmodifiedflag(false);           //   start   off   with   unmodified

return   true;
}实现打开一个位图文件
但是这是不用内存映射,
我要是用到内存映射文件,那么怎么办呢
我知道内存映射的那几个函数,但是我不知道该怎么用,不知道该在什么位置用.
主要是没有接触过内存映射文件.
帮忙谢谢
发表于:2007-07-01 18:30:361楼 得分:0
使用loadimage函数
发表于:2007-07-01 18:33:232楼 得分:0
内存映射就是分段读么

你的读文件直接用了个函数就全读到内存了

我不知道你老师要你是用到了就可以还是要节省内存消耗

你要用内存映射   先读取一部分   先进行处理啊显示   再释放内存

再读一部分进行处理。

bmp文件我没搞过   我估计也有固定的格式的   读一部分   直接显示我怕是行不通的

没有完整的bmp在内存里也可以显示?
发表于:2007-07-01 23:08:543楼 得分:0
createfilemapping创建内存映射文件;
mapviewoffile将内存映射文件映射到内存指针,这时候就可以通过这个内存指针来访问数据。
发表于:2007-07-01 23:16:244楼 得分:0
up


快速检索

最新资讯
热门点击