共有回帖数  0  个 
	 
	
	
	
     
          
          
               
				
			 
				
					 
 
            
				   - 
						
						
							 
									16BMP2H 使用说明 
功能:把一个或多个16色位图转换为一个可以被C或C++ 包含(include)的.H头文件. 
提示:开始之后,要求输入文件名,一般来说,将BMP文件放在一个较易敲打出来的路径可能是个不错的想法. 
但是,将BMP文件与16BMP2H放在同一路径可能更为方便,因为这样你可以不用打出前面的路径. 
16BMP2H 要求文件输入时带后缀!也就是文件全名. 
一般来说,.H文件输出是在程序所在目录(当前目录,运行时自动将当前目录改为程序所在目录),文件名为LOGO.H 
任何人拥有更改文件名和文件内容的权利. 
16BMP2H 并不会区别16色BMP与256,或24位的BMP,当然,你必需保证文件是16位BMP! 256色或其它格式的文件,程序本身不会出 
错,但结果显然不会如你所愿. 
另外,在使用此程序时你必须估计你的程序所能使用的静态内存,特别是 TC2或其它DOS下的编译器,实际上,本程序"为TC2设计, 
为TC2所设计",所以有一些关于内存的问题要提前声明,TC2在Model为Huge时所能用的静态内存为64K,关于Model的问题请参阅 
有关文档,所以,也就是说,如果使用16BMP2H处理大于64K的BMP(总)并产生.H,(使用这个.H时)TC2可能会报错,而除此之外,你还 
要为你原来的程序做好打算.所以使用16BMP2H时请注意,你的工程不是太大!太大时,还是建议额外的读入BMP文件好. 
编这个东西的灵感来自于网上的一篇"VB中嵌入文件的非常实现",显然这篇文件的作者(可能)不会使用资源文件,就是说这种 
笨拙的方法并不适用于VB,反而非常适用于C,实践表明,这样嵌入BMP文件,EXE本身不会剧增(大小),反而使我们极易地使用BMP 
文件编程. 
当然,不足的就是,16色显然在一些场合不够用... 
     使用静态内存确也不太聪明... 
如果你有一些好的解决以上问题的方法,不妨与我联系. 
另外附上生成logo.h的使用方法: 
正确操作生成的logo.h声明了若干个字符数组,当然,如上面所说,如果数组总大小大于64K,可能会惹来TC2的抱怨. 
生成logo.h提供一个函数--logo(x,y,index,method)用于输出以上数组所包含的BMP图象(实际上是putimage格式) 
其中x,y是要显示的屏幕坐标,index是包含进时图象的次序,制作时第一个输入的BMP为1,第二个为2,...要注意的是 
这个index是从1开始,.H本身并不提供原来BMP文件的任何标识,这意味着,你在生成logo.h后,可能无法得知原来BMP与index 
的对应关系,假如你没有把你输入的次序记下来的话.   对于method的话,它实际是图象的输出方式,graphics.h中有定义: 
COPY_PUT, XOR_PUT, AND_PUT, OR_PUT, NOT_PUT,相关作用请参阅其它文档. 
对于使用自行生成的logo.h所产生的任何后果,16BMP2H作者不承担任何责任. 
文曦畅 
/*****************************代码*************************************/ 
#include stdio.h 
#include dir.h 
#include dos.h 
#include string.h 
char *malloc(); 
int BmpToTmpFile(char *bmpFile, int index){ 
    unsigned char outPutName[15]; 
    unsigned char c[8], scanTimes, scanPixs; 
    unsigned char wkPos; 
    int i, j, k, n, crtPos, imgWh, imgHt; 
    static int color[16] = {0,4,2,6,1,5,3,7,8,12,10,14,9,13,11,15}; 
    unsigned char wkLine[640], scLine[640]; 
    FILE *fp, *tmpFileP; 
    union{ 
        unsigned char value; 
        struct{ 
            unsigned cl:4; 
            unsigned ch:4; 
        }color; 
    }mycolor; 
    if((fp = fopen(bmpFile, "rb")) == NULL) { 
        printf("Open File Error!n"); 
        return(0); 
    } 
    sprintf(outPutName, "BMP2H%d.TMP", index); 
    tmpFileP = fopen(outPutName, "wb"); 
    fseek(fp, 18, SEEK_SET); 
    imgWh=0; imgHt=0; 
    fread(&imgWh, 4, 1, fp); 
    fread(&imgHt, 4, 1, fp); 
    printf("Width: %d, Height: %dn", imgWh, imgHt); 
     
    if(imgWh==0 || imgHt==0 || imgWh640 || imgHt480){ 
        fclose(fp); 
        fclose(tmpFileP); 
        return(0); 
    } 
    imgWh--; 
    imgHt--; 
    scanTimes = imgWh / 8 + 1; 
    scanPixs = scanTimes * 4; 
    fputc(imgWh % 256, tmpFileP); 
    fputc(imgWh / 256, tmpFileP); 
    fputc(imgHt % 256, tmpFileP); 
    fputc(imgHt / 256, tmpFileP); 
     
    fseek(fp, -scanPixs, SEEK_END); 
    for(j = 0; j = imgHt; j++){ 
        crtPos = 0; 
    fread(scLine, scanPixs, 1, fp); 
        fseek(fp, -scanPixs * 2, SEEK_CUR); 
        for(n = 3; n = 0; n--){ 
            for(i = 0; i  scanTimes; i++){ 
                wkPos = 0; 
                for(k = 0; k  4; k++){ 
                    mycolor.value = scLine[i * 4 + k]; 
                    c[k * 2] = color[mycolor.color.ch]; 
                    c[k * 2 + 1] = color[mycolor.color.cl]; 
                } 
                for(k = 0; k  8; k++) 
                    wkPos += (c[k]  n & 1)  (7 - k); 
                wkLine[crtPos] = wkPos; crtPos++; 
            } 
        } 
        fwrite(wkLine, scanPixs, 1, tmpFileP); 
    } 
    fclose(fp); 
    fclose(tmpFileP); 
    return(1); 
}
main(){ 
    char fileKill[30]; 
    char fName[50]; 
    int fCount = 1, i; 
    unsigned long n, tmpN; 
    char buf[50]; 
    FILE *hp, *tmp; 
    long codeNum = 0; 
    int key = 0; 
    unsigned char *buffer; 
    struct ffblk *ff; 
     
        system("cls"); 
        printf("ttttProgrammer :Wen Xichang.nntttttGDUFSn"); 
        printf("ttt     Xichang.wen@yahoo.com.cnnnn"); 
        printf("******************************************nn"); 
        printf("ttVER 1.0nn"); 
        printf("This program make a ".h" file that includesn"); 
        printf("ONE or MORE  16-color-BMP(s) file.nn"); 
        printf("You can Use "logo()" mathod to PAINT the BMP file(s)n"); 
        printf("WITHOUT loading the BMP file(s)!nn"); 
        printf("But, MAKE SURE that the BMP files are 16-color formatted!n"); 
        printf("And SMALL!!!(  64K)nn"); 
        printf("******************************************nn"); 
    printf("Press Any key to start...n    (Or Q to quit.)"); 
    key = getche(); 
    if (key == 'q' || key == 'Q') exit(0); 
     
    for(;;){ 
        printf("nPlease input the name of the %dth BMP file.n:", fCount); 
        gets(fName); 
        if(BmpToTmpFile(fName, fCount)) 
            fCount++; 
        printf("nAdd another?(Y/N)"); 
        key = getche(); 
        if(key == 'N' || key == 'n') break; 
    } 
    if((hp = fopen("logo.h", "w+")) == NULL) { 
  printf("Open or Create a File Error!"); 
        return(0); 
    } 
    printf("nnPlease wait...n"); 
    fputs("/*logo.hn *此文件由16BMP2H自动生成.n *本文件提供logo(x,y,index,method)函数在屏幕x,y处以method方式输出第index个图象.n */nn", hp); 
    fputs("#include graphics.hnn", hp); 
    for(i = 1; i  fCount; i++){ 
        sprintf(buf, "char logoBmp%d[]={", i); 
        fputs(buf, hp); 
        codeNum = 0; 
        sprintf(buf, "BMP2H%d.TMP", i); 
        tmp=fopen(buf,"rb"); 
        findfirst(buf,ff,FA_ARCH); 
        printf("nSize:%un",ff-ff_fsize); 
         
        if((buffer=malloc(ff-ff_fsize))==NULL){ 
            printf("Not enough Memory.(molloc failed)."); 
            getch(); 
            exit(0); 
        } 
        n=0; 
        while(!feof(tmp)){ 
            buffer[n]=fgetc(tmp); 
            n++; 
        } 
        fclose(tmp); 
         
        sprintf(fileKill, "del %s", buf); 
        system(fileKill); 
        tmpN=n-1; 
        sprintf(buf, "%u", buffer[0]); 
        fputs(buf,hp); 
        for(n = 1,codeNum = 0; ntmpN;n++){ 
            fputc(',',hp); 
             
            printf("%ldbbbbbbbbbb",++codeNum); 
            if(codeNum % 30 == 0) 
                fputc('n', hp); 
                 
            sprintf(buf, "%u", buffer[n]); 
            fputs(buf,hp); 
        } 
        fputs("};nn", hp); 
        free(buffer); 
        printf("n%d Done!n", i); 
    } 
    fputs("nnint logo(int x, int y, int index, int method){n", hp); 
    fputs("tswitch(index){n", hp); 
    for(i = 1; i  fCount; i++){ 
        sprintf(buf, "ttcase %d:n", i); 
        fputs(buf, hp); 
        sprintf(buf, "tttputimage(x,y,logoBmp%d,method);n", i); 
        fputs(buf, hp); 
        fputs("tttbreak;n", hp); 
    } 
    fputs("t}n}", hp); 
    fclose(hp); 
    printf("nALL DONE!!nn"logo.h" writed!nnPress any key to exit..."); 
    getch(); 
}
/*********************************代码结束********************************/ 
本程序在编译时会有2/3个warning...不要紧,生成exe就没此问题。 
在TC2+winXP下通过.
							 
							 
							 
							  
							  
							  楼主 2016-03-16 17:46 回复
						 
						 
           
          
          
         
   
         
      
 
   
             
                  
                  
 
 
 
     
	 
  
	Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号
	
	意见反馈 | 
	关于直线 | 
	版权声明 | 
	会员须知