線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1532
推到 Plurk!
推到 Facebook!

讀raw檔顯示在image原件上較快速的方法?

尚未結案
adamjr
一般會員


發表:4
回覆:5
積分:1
註冊:2004-09-03

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-09-21 11:52:25 IP:140.123.xxx.xxx 未訂閱
我的程式是要讀進raw檔 直接顯示在image元件上 我的方法從讀檔到顯示出來要1秒多 感覺滿慢的 請問有沒有較快的方法可以做到此要求的?     
 
void __fastcall TForm1::Button1Click(TObject *Sender)
{
        width=217;
        high=390;
        w=h=h_top=0;
        if (OpenDialog1->Execute())
        {
                TMemoryStream* bin=new TMemoryStream();
                       bin->LoadFromFile(OpenDialog1->FileName);
                int dwSize=bin->Size;
                pixel=new BYTE[dwSize];
                bin->Read(pixel, dwSize);
                for (int y=0,count=0; y < high ; y  )
                 {
                          for (int x=0 ; x < width ; x  )
                          {
                                Image1->Canvas->Pixels[x][y]=RGB  (pixel[count],pixel[count],pixel[count]);
                                count=count 1;
                          }
                 }
                 delete bin;
        }
}    
發表人 - adamjr 於 2004/09/21 12:02:07
TheMoon
中階會員


發表:17
回覆:95
積分:67
註冊:2002-06-05

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-09-21 15:13:02 IP:202.39.xxx.xxx 未訂閱
用ScanLine的方式作修改,應該可以加快處理速度, 將您的程式略作修改如下:< class="code"> void __fastcall TForm1::Button1Click(TObject *Sender) { int width=217; int height=390; Byte *ptr; if(OpenDialog1->Execute()) { TMemoryStream* bin=new TMemoryStream(); bin->LoadFromFile(OpenDialog1->FileName); int dwSize=bin->Size; Byte *pixel=new BYTE[dwSize]; bin->Read(pixel, dwSize); Graphics::TBitmap *bmp = new Graphics::TBitmap(); bmp->PixelFormat=pf24bit; bmp->Height=height; bmp->Width=width; for(int y=0; yScanLine[y]; for(int x=0; xPicture->Assign(bmp); delete bmp; delete bin; } }
adamjr
一般會員


發表:4
回覆:5
積分:1
註冊:2004-09-03

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-09-21 17:09:46 IP:140.123.xxx.xxx 未訂閱
感謝 的確快非常非常多 另外請問一下 Image1->Picture->Assign(bmp); 跟 Image1->Canvas->Draw(0,0,bmp); 差異在什麼地方
TheMoon
中階會員


發表:17
回覆:95
積分:67
註冊:2002-06-05

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-09-21 18:38:58 IP:202.39.xxx.xxx 未訂閱
引言: 感謝 的確快非常非常多 另外請問一下 Image1->Picture->Assign(bmp); 跟 Image1->Canvas->Draw(0,0,bmp); 差異在什麼地方
前者:(TPicture::Assign) Copies one object to another by copying the contents of that object to the other. When Source is a object type that is valid for the Graphic property, Assign makes that graphic the value of the Graphic property. The actions performed by Assign depend on the actual types of the TPicture Graphic property and Source. For example, if the Graphic property and Source are bitmaps (TBitmap), the bitmap contained in Source is copied into the Graphic property. 後者:(TCanvas::Draw) Renders the graphic specified by the Graphic parameter on the canvas at the location given by the coordinates (X, Y). Call Draw to draw a graphic on the canvas. Draw calls the Draw method of the graphic. The image is rendered into a rectangle determined by the size of the graphic, with the upper left corner at the point (X, Y).
節錄自 Borland C   Builder Help
發表人 -
綾小路
一般會員


發表:2
回覆:12
積分:7
註冊:2004-09-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-09-24 14:57:23 IP:61.219.xxx.xxx 未訂閱
插個花  改這樣會更快    
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  int width=217;
  int height=390;
  Byte *ptr;      if(OpenDialog1->Execute())
  {
    TMemoryStream* bin=new TMemoryStream();
    bin->LoadFromFile(OpenDialog1->FileName);
    int dwSize=bin->Size;
    Byte *pixel=new BYTE[dwSize];
    bin->Read(pixel, dwSize);        Graphics::TBitmap *bmp = new Graphics::TBitmap();
    bmp->PixelFormat=pf24bit;
    bmp->Height=height;
    bmp->Width=width;

    int  w2=0;        for(int y=0,w2=0; yScanLine[y];
      for(int x=0; xPicture->Assign(bmp);
    delete bmp;
    delete bin;
  }
}
這樣改的話..即使1600x1200也是很快的 不過為什麼只做灰階? 發表人 - 綾小路 於 2004/09/24 15:04:47
cc12345
一般會員


發表:32
回覆:35
積分:13
註冊:2005-01-24

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-01-28 16:08:12 IP:61.219.xxx.xxx 未訂閱
那請問, pixel這個東西要在哪裡delete ?    
引言: 插個花 改這樣會更快
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  int width=217;
  int height=390;
  Byte *ptr;      if(OpenDialog1->Execute())
  {
    TMemoryStream* bin=new TMemoryStream();
    bin->LoadFromFile(OpenDialog1->FileName);
    int dwSize=bin->Size;
    Byte *pixel=new BYTE[dwSize];
    bin->Read(pixel, dwSize);        Graphics::TBitmap *bmp = new Graphics::TBitmap();
    bmp->PixelFormat=pf24bit;
    bmp->Height=height;
    bmp->Width=width;

    int  w2=0;        for(int y=0,w2=0; yScanLine[y];
      for(int x=0; xPicture->Assign(bmp);
    delete bmp;
    delete bin;
  }
}
這樣改的話..即使1600x1200也是很快的 不過為什麼只做灰階? 發表人 - 綾小路 於 2004/09/24 15:04:47
系統時間:2024-05-17 10:19:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!