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

BCB 如何讀.RAW檔

尚未結案
eecomcc
一般會員


發表:1
回覆:1
積分:0
註冊:2005-04-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-04-10 15:15:17 IP:140.114.xxx.xxx 未訂閱
我現在有一張.RAW檔的影像…請問 如何將讀取bmp檔的程式改寫成可讀取.raw檔的程式呢    #include  #pragma hdrstop #include "Unit1.h" #include "jtable.h" #include //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; JBLOCK *IBlock, *RBlock; unsigned char **IMatrix, **RMatrix; int IBlockOpen, IBlockNum; int IMatrixOpen = 0; int ImageOpen=0; int ImageHeight=0, ImageWidth=0; int RBlockOpen=0, RMatrixOpen=0; //read int rb=0, rxb=0, ryb=0, rx=0, ry=0, xb_tlen, yb_tlen; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Open1Click(TObject *Sender) { int i, j, u, v, xb_num, yb_num; /* 利用對話視窗開啟一個影像檔 */ if ( OpenPictureDialog1->Execute() ){ Memo1->Clear(); /* 釋放先前開啟影像所用的記憶體 */ if (IMatrixOpen == 1){ for (i=0; iVisible=false; ImageOpen=1; Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName); ImageHeight = Image1->Picture->Height; ImageWidth = Image1->Picture->Width; /* Change Image Object Size */ Image1->Height = ImageHeight; Image1->Width = ImageWidth; Image1->Visible=true; /* Data information */ /* Consider IBlockValue */ yb_num=ImageHeight/8; xb_num=ImageWidth/8; if(ImageHeight%8) yb_num ; if(ImageWidth%8) xb_num ; IBlockNum = xb_num*yb_num; xb_tlen = xb_num*8; yb_tlen = yb_num*8; } /* Memory allocate */ try{ /* IMatrix */ IMatrix = new unsigned char *[yb_tlen]; for (i=0; iCanvas->Pixels[j][i])) (0.59*GetGValue(Image1->Canvas->Pixels[j][i])) (0.11*GetBValue(Image1->Canvas->Pixels[j][i])); /* about block side */ for(i=ImageHeight; iLines->Add(s); s = ""; } */ /* 將image資料存入IBlock結構中 */ for(u=0; uLines->Add(s); } */ /* //測試用程式區段 for(i=0; i<8; i ){ s=""; for(j=0; j<8; j ){ s = FloatToStrF(IBlock[8].dct_arr[i][j], ffNumber, 5, 2) " "; } Memo1->Lines->Add(s); } */ //測試用程式區段 /* s=""; for(i=0; i<8; i ){ for(j=0; j<8; j ){ s = IntToStr(IBlock[6].z_arr[i*8 j]) " "; } } Memo1->Lines->Add(s); */ //測試用程式區段(Z) /* s=""; for(i=0; i<64; i ){ s = IntToStr(IBlock[7].z_arr[i]) " "; } Memo1->Lines->Add(s); */ } //--------------------------------------------------------------------------- void __fastcall TForm1::btn_encodeClick(TObject *Sender) { int i,j; dif_DC = 0; /* 開啟檔案以寫入 */ if( (write = fopen("aaa.txt", "wb"))==0 ){ return; } fprintf(write," %d %d %d\n", IBlockNum, ImageWidth, ImageHeight); //s=""; //for(i=0; i<64; i ){ // s =IntToStr(IBlock[0].z_arr[i]) " "; //} //Memo1->Lines->Add(s); for(i=0; iLines->Add(s); } fclose(write); } //--------------------------------------------------------------------------- void __fastcall TForm1::btn_decodeClick(TObject *Sender) { int i=0, j=0, u=0, v=0, xb_num=0, yb_num=0; /* 釋放先前開啟影像所用的記憶體 */ if (RMatrixOpen == 1){ for (i=0; iWidth=rx; Image2->Height=ry; yb_num=ry/8; xb_num=rx/8; if(ry%8) yb_num ; if(rx%8) xb_num ; /* Memory allocate */ try{ /* RMatrix */ RMatrix = new unsigned char *[yb_num*8]; for (i=0; iLines->Add(s); s = ""; } // SHOW for (i=0;iCanvas->Pixels[j][i]=(TColor)RGB(RMatrix[i][j],RMatrix[i][j],RMatrix[i][j]); /* s=""; Memo1->Lines->Add(s); for(u=0; u<50; u ){ // Decode(&RBlock[k]); for(i=0; i<8; i ){ s=""; for(j=0; j<8; j ){ s =IntToStr(RBlock[u].y_arr[i][j]) " "; } Memo1->Lines->Add(s); } s=""; Memo1->Lines->Add(s); for(i=0; i<8; i ){ s=""; for(j=0; j<8; j ){ s =IntToStr(IBlock[u].y_arr[i][j]) " "; } Memo1->Lines->Add(s); } s=""; Memo1->Lines->Add(s); } */ //測試用 /* s=""; Memo1->Lines->Add(s); for(i=0; i<8; i ){ s=""; for(j=0; j<8; j ){ s =IntToStr(RBlock[8].z_arr[i*8 j]) " "; } Memo1->Lines->Add(s); } */ fclose(read); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { create_decodeTree(); } //--------------------------------------------------------------------------- void __fastcall TForm1::btn_testClick(TObject *Sender) { int i=0, j=0, u=0, v=0, xb_num=0, yb_num=0; /* 釋放先前開啟影像所用的記憶體 */ if (RMatrixOpen == 1){ for (i=0; iWidth=rx; Image2->Height=ry; yb_num=ry/8; xb_num=rx/8; if(ry%8) yb_num ; if(rx%8) xb_num ; /* Memory allocate */ try{ /* RMatrix */ RMatrix = new unsigned char *[yb_num*8]; for (i=0; iLines->Add(s); s = ""; } // SHOW for (i=0;iCanvas->Pixels[j][i]=(TColor)RGB(RMatrix[i][j],RMatrix[i][j],RMatrix[i][j]); /* s=""; Memo1->Lines->Add(s); for(u=0; u<50; u ){ // Decode(&RBlock[k]); for(i=0; i<8; i ){ s=""; for(j=0; j<8; j ){ s =IntToStr(RBlock[u].y_arr[i][j]) " "; } Memo1->Lines->Add(s); } s=""; Memo1->Lines->Add(s); for(i=0; i<8; i ){ s=""; for(j=0; j<8; j ){ s =IntToStr(IBlock[u].y_arr[i][j]) " "; } Memo1->Lines->Add(s); } s=""; Memo1->Lines->Add(s); } */ //測試用 /* s=""; Memo1->Lines->Add(s); for(i=0; i<8; i ){ s=""; for(j=0; j<8; j ){ s =IntToStr(RBlock[8].z_arr[i*8 j]) " "; } Memo1->Lines->Add(s); } */ fclose(read); } int w,h; //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Graphics::TBitmap* BMP = new Graphics::TBitmap(); BMP->LoadFromFile("C:\\olgol.bmp"); ShowMessage(BMP->PixelFormat); Image1->Picture->Assign(BMP); TStringList* RawData=new TStringList(); Byte* ptr=NULL; h=BMP->Height; w=BMP->Width; for(int y=0;yHeight;y ){ ptr=(Byte*)BMP->ScanLine[y]; for(int x=0;xWidth*3;x ){ RawData->Add(ptr[x]); //ShowMessage(ptr[x*3]); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { Graphics::TBitmap* BMP=new Graphics::TBitmap(); BMP->PixelFormat=pf24bit; BMP->Height=h; BMP->Width=w; TStringList* RawData=new TStringList(); RawData->LoadFromFile("RawData.txt"); Byte* ptr=NULL; int i=0; for(int y=0;yScanLine[y]; for(int x=0; xStrings[i ].ToInt(); ptr[x 1]= RawData->Strings[i ].ToInt(); ptr[x 2]= RawData->Strings[i ].ToInt(); } } Image2->Picture->Assign(BMP); delete BMP; delete RawData; } //---------------------------------------------------------------------------
m58610
初階會員


發表:22
回覆:83
積分:36
註冊:2003-09-07

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-04-10 16:18:00 IP:211.74.xxx.xxx 未訂閱
最近剛整理好的程式,參考看看  
Char* raw_file_name = open_raw_img->FileName.c_str();
fstream in_raw(raw_file_name,ios::in|ios::binary);   ///開啟檔案
Byte* ptr;
Graphics::TBitmap *TheBitmap;
TheBitmap = new Graphics::TBitmap();
TheBitmap = raw_img->Picture->Bitmap;
TheBitmap->PixelFormat = pf24bit;
TheBitmap->Width = xsize;
TheBitmap->Height = ysize;
if(color_check == false)   //如果是灰階圖片
{
   for(int y = 0; y < ysize; y  )
   {
      ptr = (Byte*)TheBitmap->ScanLine[y];
      for(int x = 0; x < xsize; x  )
      {
         ptr[x*3] = in_raw.get();
         ptr[x*3 1] = ptr[x*3];
         ptr[x*3 2] = ptr[x*3];
      }
   }
}
else
{
   for(int color = 0; color < 3; color  )
   {
      for(int y = 0; y < ysize; y  )
      {
         ptr = (Byte*)TheBitmap->ScanLine[y];
        for(int x = 0; x < xsize; x  )
        {
            ptr[x*3 color]=in_raw.get();
        }
      }
   }
}
in_raw.close();
Repaint();
 
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-04-11 00:00:20 IP:218.168.xxx.xxx 未訂閱
eecomcc您好: po程式碼的方式請參考版規說明,煩請修改謝謝您的配合 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=47262
eecomcc
一般會員


發表:1
回覆:1
積分:0
註冊:2005-04-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-04-11 02:34:47 IP:140.114.xxx.xxx 未訂閱
可不可以告訴我在哪裡修正!謝謝
系統時間:2024-05-13 22:23:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!