发信人: tiger_x() 
整理人: wenbobo(2002-08-13 10:45:45), 站内信件
 | 
 
 
我非高手,但给个例子你看看吧!(不全的哟^_^)不对可别怪我.
 #include <stdio.h>
 #include <conio.h>
 #include <string.h>
 #include "vga.h"
 #include "image.h"
 #include "error.h"
 #include "xmngr.h"
 
 extern void SetRegValue(unsigned uport,unsigned char index,unsigned ch 
 ar value);
 
 int save_page(char *name)
 {
   int i;
   FILE *fp;
   void far *sVram=(void far *)0xa0000000;
 
   if((fp=fopen(name, "wb"))==NULL)
     return ERROR_OPENFILE;
   SetRegValue(GC_INDEX,GC_ENABLE_SET_RESET,0);
   SetRegValue(GC_INDEX,GC_BITMASK,0xff);
   SetRegValue(GC_INDEX,GC_ROTATE,0);
 
   for(i=0; i<4; i++)
   {
     SetRegValue(SC_INDEX,SC_MAP_MASK,(1<<i));
     SetRegValue(GC_INDEX,GC_READ_MAP,i);
     fwrite(sVram,(unsigned int)38400l,1,fp);
   }
   fclose(fp);
   SetRegValue(SC_INDEX,SC_MAP_MASK,0x0f);
   return 0;
 }
 
 int load_page(char *name)
 {
   int i, j;
   FILE *fp;
   char far *sVram=(char far *)0xa0000000;
   int y1=60, y2=447 ;
 
   if((fp=fopen(name, "rb"))==NULL)
 	return ERROR_OPENFILE;
 
   SetRegValue(GC_INDEX,GC_ENABLE_SET_RESET,0);
   SetRegValue(GC_INDEX,GC_BITMASK,0xff);
   SetRegValue(GC_INDEX,GC_ROTATE,0);
 
   for(i=0; i<4; i++)
   {
 	SetRegValue(GC_INDEX,GC_READ_MAP,i);
 	SetRegValue(SC_INDEX,SC_MAP_MASK,(1<<i));
 	fseek( fp, i*38400L+y1*80L-1, SEEK_SET ) ;
 	for( j=y1; j<y2; j++ ) {
 		fseek( fp, 2, SEEK_CUR ) ;
 		fread(sVram+j*80+1,(unsigned int)78,1,fp);
 	}
   }
   fclose(fp);
   SetRegValue(SC_INDEX,SC_MAP_MASK,0x0f);
   return 0;
 }
 
 unsigned long xImageSize(int xstart,int ystart,int xend,int yend)
 {
   return ((unsigned long)(yend - ystart + 1)) * 4
 	 *((unsigned long)((xend/8) - (xstart/8) + 2)) + (4 * sizeof(int));
 }
 
 unsigned xGetImage(int xstart,int ystart,int xend,int yend)
 {
   int i,j;
   unsigned char far *sVram=(void far *)0xa0000000;
   long dwImagesize;
   unsigned hImage,wLinebytes,wVramofs;
   long dwImageofs;
   int a[4];
 
   if(xstart>=xend || ystart>=yend)
     return XMCB_NULL_ENTRY;
   dwImagesize=xImageSize(xstart,ystart,xend,yend);
   hImage=xAlloc(dwImagesize);
   if(hImage==XMCB_NULL_ENTRY)
 	return XMCB_NULL_ENTRY;
   a[0]=xstart;a[1]=ystart;a[2]=xend;a[3]=yend;
   Dos2X(hImage,0,a,4*sizeof(int));
   X2Dos(hImage,0,a,4*sizeof(int));
   dwImageofs=4*sizeof(int);
   SetRegValue(GC_INDEX,GC_ENABLE_SET_RESET,0);
   SetRegValue(GC_INDEX,GC_BITMASK,0xff);
   SetRegValue(GC_INDEX,GC_ROTATE,0);
   wLinebytes=((xend/8) - (xstart/8) +1);
   if (wLinebytes&0x01)
 	wLinebytes++;
   for(i=0; i<4; i++)
   {
     wVramofs=xstart/8+80*ystart;
     SetRegValue(SC_INDEX,SC_MAP_MASK,(1<<i));
     SetRegValue(GC_INDEX,GC_READ_MAP,i);
     for(j=ystart;j<=yend;j++,wVramofs+=80,dwImageofs+=wLinebytes)
       Dos2X(hImage,dwImageofs,sVram+wVramofs,wLinebytes);
   }
   SetRegValue(SC_INDEX,SC_MAP_MASK,0x0f);
   return hImage;
 }
 
 int xPutImage(unsigned hImage)
 {
   int i,j;
   unsigned char far *sVram=(void far *)0xa0000000;
   unsigned wLinebytes,wVramofs;
   long dwImageofs;
   int a[4];
   int xstart,ystart,xend,yend;
   unsigned char buf[80];
 
   if(xSize(hImage) <= (4*sizeof(int)))
     return ERROR_XIMAGE_INVALID;
   X2Dos(hImage,0,a,4*sizeof(int));
   xstart=a[0];ystart=a[1];xend=a[2];yend=a[3];
   if(xstart>=xend || ystart>=yend)
     return ERROR_XIMAGE_LOCATOR;
   if(xImageSize(xstart,ystart,xend,yend) != xSize(hImage))
 	return ERROR_XIMAGE_SIZE;
   dwImageofs=4*sizeof(int);
   SetRegValue(GC_INDEX,GC_ENABLE_SET_RESET,0);
   SetRegValue(GC_INDEX,GC_BITMASK,0xff);
   SetRegValue(GC_INDEX,GC_ROTATE,0);
   wLinebytes=((xend/8) - (xstart/8) +1);
   if (wLinebytes&0x01)
 	wLinebytes++;
   for(i=0; i<4; i++)
   {
     wVramofs=xstart/8+80*ystart;
     SetRegValue(SC_INDEX,SC_MAP_MASK,(1<<i));
     SetRegValue(GC_INDEX,GC_READ_MAP,i);
     for(j=ystart;j<=yend;j++,wVramofs+=80,dwImageofs+=wLinebytes)
       X2Dos(hImage,dwImageofs,sVram+wVramofs,wLinebytes);
   }
   SetRegValue(SC_INDEX,SC_MAP_MASK,0x0f);
   return hImage;
 }
 
 
 IMAGE.h
 #ifndef __IMAGE_H
 #define __IMAGE_H
 int save_page(char *name);
 int load_page(char *name);
 unsigned long xImageSize(int xstart,int ystart,int xend,int yend);
 unsigned xGetImage(int xstart,int ystart,int xend,int yend);
 int xPutImage(unsigned hImage);
 #endif
 
 
 
 【 在 imouse (A.C.Milan) 的大作中提到: 】
 : 或者说明一下方法.本人在编显示图片的程序时,找不到有关资料,望各位大虾助一
 : 臂之力.
 
 
 
 --      *********
      * Tiger *
      ********* 
 http://jtiger.126.com
  ※ 修改:.tiger_x 于 May 27 02:28:30 修改本文.[FROM: 202.104.46.196] ※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.104.46.196]
  | 
 
 
 |