现存程序可以正常运行了,可是当图片复原后和图片的背景不完全一样呀!大家帮忙给看一看
最下面是整个程序包
#include "graphics.h"
#include<dos.h>
#include<conio.h>
#include "stdio.h"
#include "fcntl.h"
#include "malloc.h"
#include "io.h"
#include "showbmp.c"
#include "rsvga256.h"
typedef unsigned int XMS_HANDLE;
XMS_HANDLE xms_handle; /* 伪指针 */
XMS_HANDLE xms_save_restore_handle; /* 伪指针 */
typedef struct emm {
unsigned int length;
unsigned source_handle;
unsigned long source_offset;
unsigned dest_handle;
unsigned long dest_offset;
} xmm;
xmm xms;
int far(* XMS_Function)( );
int xms_installed( )
{
_AX=0x4300;
geninterrupt(0x2f);
if(_AL==0x80)
{
_AX=0x4310;
geninterrupt(0x2f);
XMS_Function=MK_FP(_ES,_BX);
return(1);
}
else
{
printf("XMS is not installed\n!");
return(0);
}
}
int test_xms(unsigned int size)
{
_AH=8;
XMS_Function( );
if(_AX<size)
{
printf("No enough XMS to be used!\n");
return(0);
}
else
return(1);
}
unsigned int alloc_xms(unsigned int size)
{
_DX=size;
_AH=9;
XMS_Function( );
if(_AX!=1)
{
printf("XMS allocation is error\n");
return(0);
}
else
return(_DX);
}
int move_xms()
{
if(XMS_Function( ))
{
_DS=FP_SEG(&xms);
_SI=FP_OFF(&xms);
_AH=0x0b;
XMS_Function( );
if(_AX!=1)
{
printf("XMS move error! %d\n",_BL);
return(0);
}
return(1);
}
else
return(0);
}
void free_xms(unsigned int handle)
{
_DX=handle;
_AH=0x0a;
XMS_Function( );
}
/*----------------------------------------------------------- */
/* 从常规内存缓冲区buf装载到扩充内存 */
/*-----------------------------------------------------------*/
void Write_To_XMS(char *buf, unsigned int size,unsigned handle,unsigned long offset)
{
xms.length=size;
xms.source_handle = 0;
xms.source_offset = FP_SEG((void far *)buf);
xms.source_offset <<= 16;
xms.source_offset += FP_OFF((void far *)buf);
xms.dest_handle = handle;
xms.dest_offset = offset;
move_xms(&xms);
}
/*----------------------------------------------------------- */
/* 从扩充内存中读取信息到常规内存缓冲区buf */
/*-----------------------------------------------------------*/
void Read_From_XMS(char *buf,unsigned int size,unsigned handle,unsigned long offset)
{
xms.length = size;
xms.source_handle = handle;
xms.source_offset = offset;
xms.dest_handle = 0;
xms.dest_offset = FP_SEG((void far *)buf);
xms.dest_offset <<= 16;
xms.dest_offset += FP_OFF((void far *)buf);
move_xms(&xms);
}
char sssbuf[300];
void Save_Image_XMS(int POPUP_x1,int POPUP_x2,int POPUP_y1,int POPUP_y2 )
{
int i,j;
unsigned int size;
unsigned long offset = 0;
char *pp;
size = (POPUP_x2-POPUP_x1+1)*(POPUP_y2-POPUP_y1+1)/1024+1;
if (test_xms(size)==0)
puts("not enough XMS");
if ((xms_save_restore_handle = alloc_xms(size)) == 0)
puts("XMS handle Error...\n");
for (i= POPUP_y1; i<=POPUP_y2;i++)
{
size = POPUP_x2-POPUP_x1;
pp = sssbuf;
for (j= POPUP_x1; j<=POPUP_x2;j++)
*pp++ = getpixel(j,i);
Write_To_XMS(sssbuf,size,xms_save_restore_handle,offset);
offset += size;
}
}
void Restore_Image_XMS(int POPUP_x1,int POPUP_x2,int POPUP_y1,int POPUP_y2)
{
int i,j;
unsigned short size;
unsigned long offset = 0;
char *pp;
size = POPUP_x2-POPUP_x1;
for (i= POPUP_y1; i<=POPUP_y2;i++)
{
Read_From_XMS(sssbuf,size,xms_save_restore_handle,offset);
offset += size;
pp = sssbuf;
for (j= POPUP_x1; j<=POPUP_x2;j++)
putpixel(j,i,*pp++);/* sssbuf[j-POPUP_x1]); */
}
free_xms(xms_save_restore_handle);
}
int huge rReturn_SVGA256(void)
{
return(SVGA640x480x256);
}
void main()
{ int iii=DETECT, jjj=0;
int aa=30;
installuserdriver("Svga256", rReturn_SVGA256); /* 对于svga256必需执行该函数以安装BGI驱动 */
initgraph(&iii, &jjj, "");
xms_installed( ); /*初始化一定要写上*/
show_bmp("main.bmp",0,0);
Save_Image_XMS(50,139,50,176 );
getch();
show_bmp("bell.bmp",50,50);
getch();
Restore_Image_XMS(50,139,50,176);
getch();
closegraph();
}
大家帮帮忙吧,我实在是能不出来呀