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

ScanLine 範例問題

答題得分者是:RedSnow
無故障
一般會員


發表:17
回覆:69
積分:17
註冊:2004-03-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-10-24 11:58:10 IP:61.221.xxx.xxx 未訂閱
以下程式是求助檔中的ScanLine 範例 只改一行,理論上應該會顯示原來的圖案 但是為何會有對角線出現,百思不解,煩請各位大大可否解釋一下    謝謝.    
void __fastcall TForm1::Button1Click(TObject *Sender)    {
  Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
// This example shows drawing directly to the Bitmap
  Byte *ptr;
  try
  {
    pBitmap->LoadFromFile("C:\\Program Files\\Common Files\\Borland Shared\\Images\\Splash\\256color\\factory.bmp");
    for (int y = 0; y < pBitmap->Height; y  )
    {
      ptr = (Byte *)pBitmap->ScanLine[y];          for (int x = 0; x < pBitmap->Width; x  )
        ptr[y] = (Byte)x; // 修改處
    }
    Canvas->Draw(0,0,pBitmap);
  }
  catch (...)
  {
    ShowMessage("Could not load or alter bitmap");
  }
  delete pBitmap;
}    
練習! 練習! 再練習!
------
嘿嘿嘿
RedSnow
版主


發表:79
回覆:1322
積分:845
註冊:2003-12-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-10-24 18:49:57 IP:61.217.xxx.xxx 未訂閱
無故障 您好:    在您標示著 "修改處" 的那一行敘述中,x 值是迴圈產生的,範圍是 0 至圖像的寬度,您將這個值設給 pBitmap 的作用為何,可以請您說明一下嗎? 如果您想要在 Form 上顯示 "原來的圖案",那麼在 pBitmap 使用 LoadFromFile 來載入檔案後,直接使用 Canvas->Draw() 就已經可以將圖檔內容畫到 Form 上了,無需執行那兩個迴圈。 那條 "對角線" 的出現,是因為您使用了 y loop 讓 ptr 由上至下去接收 pBitmap 的每條橫線資料,但是您在第二個迴圈 (x loop) 中,並未以 ptr[x] 而是以 ptr[y] 去處理圖素資料,這個 y 值會在每往下處理一行圖素資料時加一,因此那個 ptr[y] 會在每往下處理一行資料時,即往右方偏移一個點的位置,因此才會一路向下向右產生一條斜線。 7 天天敲鍵盤 v 時時按滑鼠 8
無故障
一般會員


發表:17
回覆:69
積分:17
註冊:2004-03-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-10-24 19:59:32 IP:140.134.xxx.xxx 未訂閱
感謝解惑,因為原範例程式碼如下 只會 Show 條紋 , 並看不出該程式有什麼功能,各位大大 可以按F1查看範例就知道了    
    void __fastcall TForm1::Button1Click(TObject *Sender)    {
  Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
// This example shows drawing directly to the Bitmap
  Byte *ptr;
  try
  {
    pBitmap->LoadFromFile("C:\\Program Files\\Common Files\\Borland Shared\\Images\\Splash\\256color\\factory.bmp");
    for (int y = 0; y < pBitmap->Height; y  )
    {
      ptr = (Byte *)pBitmap->ScanLine[y];          for (int x = 0; x < pBitmap->Width; x  )
        ptr[x] = (Byte)y; // 原程式碼
    }
    Canvas->Draw(0,0,pBitmap);
  }
  catch (...)
  {
    ShowMessage("Could not load or alter bitmap");
  }
  delete pBitmap;
}    
練習! 練習! 再練習! 發表人 - 無故障 於 2005/10/24 20:00:59
------
嘿嘿嘿
系統時間:2024-05-10 14:36:32
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!