高手来看一下我的这个程序的出错!
高手来看一下我的这个程序的出错!
楼主fishrot()2003-08-05 22:33:11 在 C/C++ / C语言 提问 //ManiBMP.H
//BMP类的声明
//成员函数在ManiBMP.H中定义
#include<stdlib.h>
#ifndef ManiBMP_H
#define ManiBMP_H
class Pixel24{
friend class BMP;
private:
short sRed;
short sGreen;
short sBlue;
};
class BMP{
public:
BMP();
int LoadFile(const char* filename);
void ShowInfo(void);
private:
char cFileTag; //Type of file
DWORD iFileSize; //Size of file
DWORD iReversed; //Always be zero
DWORD iBDO; //Bitmap Data Offset
DWORD iBHS; //Bitmap Header Size
DWORD iWidth; //Width of the bitmap
DWORD iHeight; //Height of the bitmap
WORD iPlanes; //Planes of the bitmap, always be 1
WORD iBPP; //Bits Per Pixel
DWORD iCompression; //Method of compression
DWORD iBDS; //Bitmap Data Size
DWORD iHRes; //Horizontal Resolution
DWORD iVRes; //Vertical Resolution
DWORD iColors; //Colors to be used
DWORD iImpColors; //Important colors
void LoadBuffer(WORD &,int,char*);
void LoadBuffer(DWORD &,int,char*);
Pixel24 BMap;
};
# endif
//ManiBMP.cpp
//处理BMP
#include<windows.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>
#include<assert.h>
#include"ManiBMP.h"
BMP::BMP(){
char* szFilePath=new char;
cout<<"Input the filepath:";
cin>>szFilePath;
LoadFile(szFilePath);
BMap= new Pixel24;
}
void BMP::ShowInfo(){
cout<<"FileTag="<<(char)cFileTag<<(char)cFileTag<<endl;
cout<<"Filesize:"<<iFileSize<<endl;
cout<<"Reversed:"<<iReversed<<endl;
cout<<"Bitmap Data Offset:"<<iBDO<<endl;
cout<<"Bitmap Header Size:"<<iBHS<<endl;
cout<<"Width:"<<iWidth<<endl;
cout<<"Height:"<<iHeight<<endl;
cout<<"Planes:"<<iPlanes<<endl;
cout<<"Bits Per Pixel:"<<iBPP<<endl;
cout<<"Compression:"<<iCompression<<endl;
cout<<"Bitmap Data Size:"<<iBDS<<endl;
cout<<"Horizontal Resolution:"<<iHRes<<endl;
cout<<"Vertical Resolution:"<<iVRes<<endl;
cout<<"Colors:"<<iColors<<endl;
cout<<"Important Colors:"<<iImpColors<<endl;
return;
}
void BMP::LoadBuffer(WORD &dest,int count,char* cBuffer){
dest=0;
for(int i=count-1;i>=0;i--){
dest<<=8;
dest+=cBuffer;
}
}
void BMP::LoadBuffer(DWORD &dest,int count,char* cBuffer){
dest=0;
for(int i=count-1;i>=0;i--){
dest<<=8;
dest+=cBuffer;
}
}
int BMP::LoadFile(const char* szFilename){
char cBuffer;
ifstream in(szFilename);
assert(in);
in.get(cBuffer,3);
cFileTag=cBuffer;
cFileTag=cBuffer;
in.get(cBuffer,5);
LoadBuffer(iFileSize,4,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iReversed,4,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iBDO,4,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iBHS,4,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iWidth,4,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iHeight,4,cBuffer);
in.get(cBuffer,3);
LoadBuffer(iPlanes,2,cBuffer);
in.get(cBuffer,3);
LoadBuffer(iBPP,2,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iCompression,4,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iBDS,4,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iHRes,4,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iVRes,4,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iColors,4,cBuffer);
in.get(cBuffer,5);
LoadBuffer(iImpColors,4,cBuffer);
for(unsigned int i=0;i<iHeight;i++){
for(unsigned int j=0;j<=iWidth;i++){
in.get(cBuffer,2);
BMap.sBlue=cBuffer;
in.get(cBuffer,2);
BMap.sGreen=cBuffer;
in.get(cBuffer,2);
BMap.sRed=cBuffer;
}
}
return 1;
}
void main()
{
BMP bmpSample;
bmpSample.ShowInfo();
}
出错位置在ManiBMP.cpp的类BMP的构造函数的为类型为Pixel24的数组BMap分配空间的地方,错误是:
E:\doc_trans\PROGRAM\Lab\BMPTest1\ManiBMP.cpp(16) : error C2440: "=" : cannot convert from "class Pixel24 (*)" to "class Pixel24 "
There are no conversions to array types, although there are conversions to references or pointers to arrays
我的目的是给Bmap分配一个1024*768的空间,请高手告诉我问题所在以及解决的方法。 问题点数:50、回复次数:2Top
1 楼fireseed(【VC无敌,英明神武,千秋万代,一统江湖!】—奶油狗)回复于 2003-08-05 22:40:03 得分 50
BMap= new Pixel24;
二维数组不是这样new滴!
关于怎样申请二维数组,请楼主不要懒,自己翻以前的贴子。
另外,我强烈建议楼主不要用二维数组存储位图,没有人这样干滴!一维数组已经足够,如果你学过线性代数的话。Top
2 楼fishrot()回复于 2003-08-05 22:49:14 得分 0
谢谢楼上的,其实用二位数组也没什么直观一点嘛。分就给你了。Top
-
相关文章
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的readygo.com.cn
