求助各位高手大侠:如何将TC30下的C++绘制的美丽钻石图形以BMP文件保存下来,源码给出,(满意解答,立即送分)在线急等!!!
该程序虽然可以调试通过,但是保存的BMP文件模糊一片,主要是因为我不会在C++下改写getimage和((tempbuffer[ 4+j/8]&bin[j%8])/bin[j%8])*0x08|……可能是这两段语句的问题,才导致位图文件写入不正确吧。两拜托各位高手大使出手赐教,感谢至极,我的email:wzhen166@163.com,QQ号码:203013786。
我对下面这段不明白:
这是张博大侠老兄的指点和提示:
如果使用TC30,这样一次可以分配足够大的内存
getimage执行一次就够了,确实在C++执行一次就可以。
另外
((tempbuffer[ 4+j/8]&bin[j%8])/bin[j%8])*0x08|
((tempbuffer[ 84+j/8]&bin[j%8])/bin[j%8])*0x04|
((tempbuffer[164+j/8]&bin[j%8])/bin[j%8])*0x02|
((tempbuffer[244+j/8]&bin[j%8])/bin[j%8])*0x01;
如果采用移位和位与位或来代替上面的运算
运算速度至少提高100倍甚至1000倍,因为getimage一行和getmage整屏幕执行时间差不了多少
这样就少执行400多次getimage,也少写了400多次磁盘,而这两点正式瓶颈之所在
至于把top和bottom颠倒,则不需要增加额外的运算。
源码如下:
/*Diamond.cpp*/
#include <graphics.h>
#include <math.h>
#include <time.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <new.h>
#include <process.h>
#include <bios.h>
#include <conio.h>
#include <malloc.h>
#include <locale.h>
#include <mem.h>
#include <iostream.h>
#define Width 640
#define Height 480
unsigned char bin[8] = {
0x80,0x40,0x20,0x10,
0x08,0x04,0x02,0x01
};
int vga_default[16][3]={
0 ,0 ,0 ,
0 ,0 ,42,
0 ,42,0 ,
0 ,42,42,
42,0 ,0,
42,0 ,42,
42,21,0 ,
42,42,42,
21,21,21,
21,21,63,
0 ,63,0 ,
0 ,63,63,
63,21,17,
63,19,63,
63,63,0 ,
63,63,63};
typedef struct BMP_file
{
unsigned short bfType;
unsigned long bfSize;
unsigned int Reserved1;
unsigned int Reserved2;
unsigned long bfOffset;
}bitmapfile;
typedef struct BMP_info
{
unsigned long biSize;
unsigned long biWidth;
unsigned long biHeight;
int biPlanes;
int biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
unsigned long biXpelspermeter;
unsigned long biYpelspermeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
}bitmapinfo;
typedef struct RGB_BMP_typ
{
unsigned char blue;
unsigned char green;
unsigned char red;
unsigned char reserved;
}RGB_BMP,*RGB_BMP_ptr;
typedef struct bmp_picture_typ
{
bitmapfile file;
bitmapinfo info;
RGB_BMP palette[256];
char far *buffer;
}bmp_picture,*bmp_picture_ptr;
void Check_Bmp(bmp_picture_ptr bmp_ptr)
{
if(bmp_ptr->file.bfType!=0x4d42)
{
printf("Not a BMP file!n");
exit(1);
}
if(bmp_ptr->info.biCompression!=0)
{
printf("Can not display a compressed bmp file!n");
exit(1);
}
if(bmp_ptr->info.biBitCount!=8)
{
printf("Not a index 256color bmp file!n");
exit(1);
}
}
void Set_BMP_Palette_Register(int index,RGB_BMP_ptr color)
{
outportb(0x3c6,0xff);
outportb(0x3c8,index);
outportb(0x3c9,color->red);
outportb(0x3c9,color->green);
outportb(0x3c9,color->blue);
}
int save_bmp()
{
FILE *fp;
int *bmp256;
int i,j,k;
long width,height;
char disfile[]="F:\\MJ-PIC\\mset.bmp";
int color;
unsigned char tempbuffer[640];
bmp_picture pic;
width=Width;height=Height;
fp=fopen(disfile,"wb");
if(fp==NULL){
printf("can not open the file!");
exit(0);
};
fseek(fp,0,SEEK_SET);
pic.file.bfType = 0x4d42;
pic.file.bfSize = 1078+width*height;
pic.file.Reserved1 = 0;
pic.file.Reserved2 = 0;
pic.file.bfOffset = 1078;
pic.info.biSize = 40;
pic.info.biWidth = width;
pic.info.biHeight= height;
pic.info.biPlanes= 1;
pic.info.biBitCount = 8;
pic.info.biCompression = 0;
pic.info.biSizeImage = width*height;
pic.info.biXpelspermeter = 3780;
pic.info.biYpelspermeter = 3780;
pic.info.biClrUsed = 0;
pic.info.biClrImportant = 0;
fwrite(&pic.file,sizeof(bitmapfile),1,fp);
fwrite(&pic.info,sizeof(bitmapinfo),1,fp);
for (i=0;i<16;i++)
{
pic.palette[i].red = vga_default[i][0]*4;
pic.palette[i].green= vga_default[i][1]*4;
pic.palette[i].blue = vga_default[i][2]*4;
}
fwrite(pic.palette,1,1024,fp);
pic.buffer = new char[660];//?
for (i=height-1;i>=0;i--)
{
/*in order to understand this,you need to know how the vga using the video memory key words:page,bit,vram */
//imagesize(0,i,width-1,i);
getimage(0,i,width-1,i,tempbuffer);
for (j=0;j<width;j++)
{
pic.buffer[j]=
((tempbuffer[ 4+j/8]&bin[j%8])/bin[j%8])*0x08|
((tempbuffer[ 84+j/8]&bin[j%8])/bin[j%8])*0x04|
((tempbuffer[164+j/8]&bin[j%8])/bin[j%8])*0x02|
((tempbuffer[244+j/8]&bin[j%8])/bin[j%8])*0x01;
}
fwrite(&pic.buffer,1,width,fp);//?
}
fclose(fp);
return 0;
}
/* */
void BMP_Delete(bmp_picture_ptr image)
{
delete(image->buffer);//?
}
main()
{
float q;
int x=320,y=240,r=185;
int i,j,n=20;
int a[100],b[100];
int graphdriver=DETECT, graphmode;
initgraph(&graphdriver,&graphmode,"..\\bgi");
cleardevice();
setbkcolor(9);
setcolor(4);
circle(x,y,r);/*画圆,输入x=320,y=240可使圆心位于屏幕中心*/
q=360/n;/*角增量*/
q=q*3.1415926/180;/*将角增量化为弧度*/
for (i=1;i<=n;i++)/*计算n个点的坐标*/
{
a[i]=(int)(x+r*cos((i-1)*q));
b[i]=(int)(y-r*sin((i-1)*q));
}
for (i=1;i<=n-1;i++)/*各点连线*/
{
for (j=i+1;j<=n;j++)
line(a[i],b[i],a[j],b[j]);
}
if (getch()=='s')
{
outtextxy(0,25,"The picture is saving now!");
save_bmp();
outtextxy(0,450,"The picture had saving ok!");
}
getch();
closegraph();
return (0);
}
急切盼望指教!!!
问题点数:0、回复次数:15Top
1 楼wzhen001(小浪)回复于 2005-06-04 18:10:14 得分 0
希望张博和其他高手能看到这个帖子,在线急等,速请高手出入相助!!!也可以与我QQ联系。Top
2 楼mostideal(三甲)回复于 2005-06-05 13:13:29 得分 0
没做过,,只能帮你顶了。。Top
3 楼cooljjyy(叽叽歪歪)回复于 2005-06-05 14:09:34 得分 0
又想起当年玩TC2.0的回忆了,没想到现在还有人用DOS下的VGA模式作图 :)
现在没有TC了,不能帮你看代码,不过我有一个偷工的办法。
就是在windows的窗口模式运行,然后再print screen...
或者你可以去找DOS下的FPE(整人专家),用热键就能把屏幕上的内容抓下来。
又是一个经典工具哈哈。以前DOS下很多类似的工具的。DOS时代真让人怀念Top
4 楼wzhen001(小浪)回复于 2005-06-05 16:40:36 得分 0
请熟悉TC3.0 BMP结构的高手关注一下。问题的关键其实就是内存的分配和getimage。可是我怎么试都不行呢?请感兴趣的朋友强烈关注!Top
5 楼wzhen001(小浪)回复于 2005-06-05 18:51:56 得分 0
强烈呼吁高手再现,王者归来,指点迷津!!!Top
6 楼cc888(萝卜腌菜)回复于 2005-06-05 23:28:15 得分 0
高手都忙着赚钱养家糊口去了.
那有时间看这么长的代码.Top
7 楼lingehu25(林)回复于 2005-06-05 23:44:31 得分 0
哈哈。
用截图工具吧,没办法了,我一般都是这么说的。呵呵。
SuperCapure 3.43 我用的是这个软件。
截下来的图绝对是BMP的格式的。
哈哈……(顶一下)。Top
8 楼sea2000cn(我想我是海)回复于 2005-06-06 07:52:09 得分 0
实在不行,Printscreen :)Top
9 楼wosirius(神经第六)回复于 2005-06-06 09:12:25 得分 0
真郁闷 贴了一段 居然说代码太长:(Top
10 楼wzhen001(小浪)回复于 2005-06-06 11:41:13 得分 0
请各位铁杆好友继续支持,强顶一下,再次请高手关注!!!谢谢大家!Top
11 楼wzhen001(小浪)回复于 2005-06-06 18:14:09 得分 0
强烈呼唤高手现身!!!Top
12 楼wzhen001(小浪)回复于 2005-06-07 07:58:36 得分 0
请网友支持,再顶!!!Top
13 楼xiao_xiao_zi(笑小子)回复于 2005-06-07 08:31:25 得分 0
用GD库
一个免费的图形输出库
可以支持多种图象格式多种语言Top
14 楼wzhen001(小浪)回复于 2005-06-08 19:48:23 得分 0
各位网友再顶啊,呼唤高手重现江湖!!!Top
15 楼wzhen001(小浪)回复于 2005-06-09 08:05:55 得分 0
请各位高手大侠,英雄豪杰看过来!!!Top




