| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 793 人关注过本帖
标题:【求助】关于图形函数
只看楼主 加入收藏
hewenhao
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-1-10
收藏
 问题点数:0 回复次数:3 
【求助】关于图形函数

源程序如下:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>

void save_screen(void far *buf[4]);
void restore_screen(void far *buf[4]);

int maxx, maxy;

int main(void)
{
int gdriver=DETECT, gmode, errorcode;
void far *ptr[4];

/* auto-detect the graphics driver and mode */
initgraph(&gdriver, &gmode, "");
errorcode = graphresult(); /* check for any errors */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx = getmaxx();
maxy = getmaxy();

/* draw an image on the screen */
rectangle(0, 0, maxx, maxy);
line(0, 0, maxx, maxy);
line(0, maxy, maxx, 0);

save_screen(ptr); /* save the current screen */
getch(); /* pause screen */
cleardevice(); /* clear screen */
restore_screen(ptr); /* restore the screen */
getch(); /* pause screen */

closegraph();
return 0;
}

void save_screen(void far *buf[4])
{
unsigned size;
int ystart=0, yend, yincr, block;

yincr = (maxy+1) / 4;
yend = yincr;
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */

for (block=0; block<=3; block++)
{
if ((buf[block] = farmalloc(size)) == NULL)
{
closegraph();
printf("Error: not enough heap space in save_screen().\n");
exit(1);
}

getimage(0, ystart, maxx, yend, buf[block]);
ystart = yend + 1;
yend += yincr + 1;
}
}

void restore_screen(void far *buf[4])
{
int ystart=0, yend, yincr, block;

yincr = (maxy+1) / 4;
yend = yincr;

for (block=0; block<=3; block++)
{
putimage(0, ystart, buf[block], COPY_PUT);
farfree(buf[block]);
ystart = yend + 1;
yend += yincr + 1;
}
}

该程序的功能:将程序所画图形均分四块利用getimage()函数保存到内存中,然后利用putimage()函数将其恢复,但是运行到第三块区域的时候,就会报错,退出图形模式输出Error: not enough heap space in save_screen().,这是何故呀?

[此贴子已经被作者于2007-1-22 13:03:26编辑过]

搜索更多相关主题的帖子: 图形 函数 void include int 
2007-01-22 13:03
一笔苍穹
Rank: 1
等 级:新手上路
帖 子:640
专家分:0
注 册:2006-5-25
收藏
得分:0 
区域太大,存不下去了
2007-01-24 10:40
hewenhao
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-1-10
收藏
得分:0 

那为什么buf[0]和buf[1]能申请得到,而buf[2]就申请失败呢?


2007-01-24 19:04
hewenhao
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-1-10
收藏
得分:0 
dos中最多可以申请多大的内存空间呀?

2007-01-24 19:31
快速回复:【求助】关于图形函数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013686 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved