全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1393
推到 Plurk!
推到 Facebook!

BMP檔寫入後出現幾乎全黑的圖

 
brian28914
一般會員


發表:1
回覆:2
積分:0
註冊:2006-12-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2006-12-23 23:06:41 IP:140.115.xxx.xxx 未訂閱
我寫了這個用來加強BMP檔對比的程式 可是發現跑出來一個幾乎全黑的圖 我試了一下 很像是MAX 和MIN跑不出來(我適用一個Pixel一個Pixel去比較出最大和最小值) 可是看起來又沒啥錯 不知道是哪裡弄錯了?? 煩請高手大大糾正一下吧~~~前面主要是在顯示BMP的資訊後面才開始處理該圖檔 主要想處理256*256的彩色BMP

#include 
#include 
#include 
#pragma pack(1)    struct Fileheader
{  unsigned short Type;  // signature - 'BM'
unsigned  long Size;  // file size in bytes
unsigned short Reserved1; // 0
unsigned short Reserved2; // 0
unsigned long  OffBits;   // offset to bitmap
unsigned long  StructSize;// size of this struct (40)
unsigned long  Width; // bmap width in pixels
unsigned long  Height;// bmap height in pixels
unsigned short Planes;// num planes - always 1
unsigned short BitCount;  // bits per pixel
unsigned long  Compression;   // compression flag
unsigned long  SizeImage; // image size in bytes
long   XPelsPerMeter; // horz resolution
long   YPelsPerMeter; // vert resolution
unsigned long  ClrUsed;   // 0 -> color table size
unsigned long  ClrImportant;  // important color count
};        struct RGBdata
{
unsigned char B;
unsigned char G;
unsigned char R;
};     void ReadPic(char*);    unsigned char* Bmp;
Fileheader f;
RGBdata color[10000000],newimage[10000000],Max,Min;    using std::cin;
using std::cout;
using std::endl;    int main()
{
char input[30] ;
cout<<"please enter the file name(0 to exit the program):";
cin >> input ;
while ( input[0] != '0' )
{    ReadPic(input);
cout<<"-----------------------------------------"<> input ;    }    system("pause");
}    void ReadPic(char *Filename)
{
Max.R=color[0].R;   
Max.G=color[0].G; 
Max.B=color[0].B;    Min.R=color[0].R;   
Min.G=color[0].G; 
Min.B=color[0].B;     int i=0;
int j=0;     FILE *stream=fopen( Filename,"rb");
int pixel;
if (stream == NULL){
cout<<"file open error"< Max.R )
Max.R = color[i f.Width*j].R;
if ( color[i f.Width*j].R < Min.R )
Min.R = color[i f.Width*j].R;
} 
}    for ( j=0;j Max.G )
Max.G = color[i f.Width*j].G;
if ( color[i f.Width*j].G < Min.G )
Min.G = color[i f.Width*j].G;
} 
}
for ( j=0;j Max.B )
Max.B = color[i f.Width*j].B;
if ( color[i f.Width*j].B < Max.B )
Max.B = color[i f.Width*j].B;
} 
}    cout<<"Max.R:"<
brian28914
一般會員


發表:1
回覆:2
積分:0
註冊:2006-12-20

發送簡訊給我
#2 引用回覆 回覆 發表時間:2006-12-24 11:45:50 IP:140.115.xxx.xxx 未訂閱
還有.我因為會覺得是MAX和MIN有錯是因為我coutMAX和MIN後都看不到東西!
brian28914
一般會員


發表:1
回覆:2
積分:0
註冊:2006-12-20

發送簡訊給我
#3 引用回覆 回覆 發表時間:2006-12-24 21:39:40 IP:140.115.xxx.xxx 未訂閱
主要是想看程式中的這段   
for ( j=0;j {
for ( i=0;i {
if ( color[i f.Width*j].R > Max.R )
Max.R = color[i f.Width*j].R;
if ( color[i f.Width*j].R < Min.R )
Min.R = color[i f.Width*j].R;
}
}

for ( j=0;j {
for ( i=0;i {
if ( color[i f.Width*j].G > Max.G )
Max.G = color[i f.Width*j].G;
if ( color[i f.Width*j].G < Min.G )
Min.G = color[i f.Width*j].G;
}
}
for ( j=0;j {
for ( i=0;i {
if ( color[i f.Width*j].B > Max.B )
Max.B = color[i f.Width*j].B;
if ( color[i f.Width*j].B < Max.B )
Max.B = color[i f.Width*j].B;
}
}

cout<<"Max.R:"< <<"Max.G:"< <<"Max.B:"< <<"Min.R:"< <<"Min.G:"< <<"Max.B:"< <
系統時間:2024-04-20 19:35:29
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!