伙计们,我是 C++ 的新程序员,请你帮我编写一个程序,在不使用 OpenCV 的情况下,在 Visual C++ 中以位图 24 位彩色图像绘制蓝色矩形。同样在 VS C++ 中,我无法获得标题 graphics.h 而不是我使用的 shud。我必须在图像中绘制一个矩形而不是线条这是我在 VS-C++ 中的代码,它只在底部显示一条黑线:
void copy_Header(FILE *,FILE *);
void main()
{
FILE *src; int offset; int width, height;
fopen_s(&src,"jaguar.bmp","rb");
FILE *dest;
fopen_s(&dest,"rect_image.bmp","wb");
fseek(src,10,SEEK_SET);
fread(&offset,4,1,src);
fseek(src,18,SEEK_SET);
fread(&width,4,1,src);
fseek(src,22,SEEK_SET);
fread(&height,4,1,src);
copy_Header(src,dest);
fseek(src,offset,SEEK_SET);
fseek(dest,offset,SEEK_SET);
unsigned char x=(unsigned char)fgetc(src);
double r,g,b,z[3];
int i;
unsigned char ch[3];
b=ch[0]=fgetc(src);
g=ch[1]=fgetc(src);
r=ch[2]=fgetc(src);
for (int j=0;j<4;j++)
{
for(; offset<width; offset++)
{
z[0]=b;
z[1]=0;
z[2]=0;
fputc(z[0],dest);
fputc(z[1],dest);
fputc(z[2],dest);
}
}
fseek(src,4096,SEEK_SET);
fseek(dest,4096,SEEK_SET);
unsigned char y= (unsigned char)fgetc(src);
while(!feof(src))
{
fputc(y,dest);
y=(unsigned char)fgetc(src);
}
fclose(src);
fclose(dest);
puts("Image Copied");
_getch();
}
void copy_Header(FILE *srcImage,FILE *dstImage)
{
unsigned char *ptrc= (unsigned char *)malloc(54*sizeof(char));
fseek(srcImage,0,SEEK_SET);
fseek(dstImage,0,SEEK_SET);
fread(ptrc,54,1,srcImage);
fwrite(ptrc,54,1,dstImage);
}
提前谢谢。图像大小为 1024 x 1024,是 24 位图文件。