|
1楼 功能:把一个或多个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作者不承担任何责任. 文曦畅 广外软件工程(2) QQ:375020128 E-Mail:xichang.wen@yahoo.com.cn |
|
|
|
- 共有16篇贴子
|
2楼 #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: %d\n", imgWh, imgHt); if(imgWh==0 || imgHt==0 || imgWh>640 || imgHt>480){ 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; |
|
|
|
|
3楼 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); } |
|
|
|
|
4楼 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("\t\t\t\tProgrammer :Wen Xichang.\n\n\t\t\t\t\tGDUFS\n"); printf("\t\t\t Xichang.wen@yahoo.com.cn\n\n\n"); printf("******************************************\n\n"); printf("\t\tVER 1.0\n\n"); printf("This program make a \".h\" file that includes\n"); printf("ONE or MORE 16-color-BMP(s) file.\n\n"); printf("You can Use \"logo()\" mathod to PAINT the BMP file(s)\n"); printf("WITHOUT loading the BMP file(s)!\n\n"); printf("But, MAKE SURE that the BMP files are 16-color formatted!\n"); printf("And SMALL!!!( < 64K)\n\n"); printf("******************************************\n\n"); 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) { |
|
|
|
|
5楼 return(0); } printf("\n\nPlease wait...\n"); fputs("/*logo.h\n *此文件由16BMP2H自动生成.\n *本文件提供logo(x,y,index,method)函数在屏幕x,y处以method方式输出第index个图象.\n */\n\n", hp); fputs("#include <graphics.h>\n\n", 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:%u\n",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; n<tmpN;n++){ fputc(',',hp); printf("%ld\b\b\b\b\b\b\b\b\b\b",++codeNum); if(codeNum % 30 == 0) fputc('\n', hp); sprintf(buf, "%u", buffer[n]); fputs(buf,hp); } fputs("};\n\n", hp); free(buffer); printf("\n%d Done!\n", i); } fputs("\n\nint logo(int x, int y, int index, int method){\n", hp); fputs("\tswitch(index){\n", hp); for(i = 1; i < fCount; i++){ sprintf(buf, "\t\tcase %d:\n", i); fputs(buf, hp); sprintf(buf, "\t\t\tputimage(x,y,logoBmp%d,method);\n", i); fputs(buf, hp); fputs("\t\t\tbreak;\n", hp); } fputs("\t}\n}", hp); fclose(hp); printf("\nALL DONE!!\n\n\"logo.h\" writed!\n\nPress any key to exit..."); getch(); } |
|
|
|
|
6楼 本程序在编译时会有2/3个warning...不要紧,生成exe就没此问题。 在TC2+winXP下通过. |
|
|
|
|
9楼 先编好一个可以显示图片的程序,图片从自己(这个可执行文件)中的固定位置(先假设偏移量是 12600)读出。 编译后看看可执行文件的大小,假设是 32123 Byte。 把这个程序中读取图片的位置(偏移量)改成 32123。重新编译。 以后只要把图片复制在这个程序的后面就可以了。 用 copy 命令,你也可以写一个程序来完成这个工作。 广外女生/广外男生 可不是病毒,说好听点是远程控制软件,难听点的叫木马。视乎你怎么用。刀可以切菜,也可以杀人~~~ |
|
|
|
|
11楼 有空的,闲的没事的,想练练手艺的,可以把这个程序改成自动分辨调色板的。 关于bmp文件格式,可以上网搜,也可以看置顶 |
|
|
|
| 61.167.60.* |
12楼 就是我用TC画了一个图形,我想把这个图形拷到word上打印,我试过用键盘上得print screen ,在word里面粘贴时却只有回车符,我也试过抓屏软件,可是没法用啊。 请问你知道有什么方法可以完成吗?谢谢你了 |
|
|
| 61.167.60.* |
13楼 |
|
|
| 121.15.77.* |
16楼 |
|
|
