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

程式執行錯誤

尚未結案
trent0131
一般會員


發表:6
回覆:5
積分:2
註冊:2008-07-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-08-10 11:22:16 IP:123.194.xxx.xxx 訂閱


  1. #include
  2. #pragma hdrstop
  3. #include "Unit1.h"
  4. //---------------------------------------------------------------------------
  5. #pragma package(smart_init)
  6. #pragma resource "*.dfm"
  7. TForm1 *Form1;
  8. //---------------------------------------------------------------------------
  9. __fastcall TForm1::TForm1(TComponent* Owner)
  10. : TForm(Owner)
  11. {
  12. }
  13. //---------------------------------------------------------------------------
  14. void __fastcall TForm1::Button1Click(TObject *Sender)
  15. {
  16. Close();
  17. }
  18. //---------------------------------------------------------------------------
  19. void __fastcall TForm1::Button2Click(TObject *Sender)
  20. {
  21. if (OpenPictureDialog1->Execute())
  22. {
  23. Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
  24. }
  25. }
  26. //---------------------------------------------------------------------------
  27. void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
  28. int X, int Y)
  29. {
  30. double r,g,b;
  31. int height,width;
  32. Graphics::TBitmap *TheBitMap;
  33. Byte *ptr1;
  34. TheBitMap=Image1->Picture->Bitmap;
  35. height=Image1->Picture->Height;
  36. width=Image1->Picture->Width;
  37. //TheBitMap->PixelFormat=pf8bit;
  38. if(Y
  39. {
  40. ptr1=(Byte*)Image1->Picture->Bitmap->ScanLine[Y];
  41. Label1->Caption=ptr1[X*3 2];
  42. Label2->Caption=ptr1[X*3 1];
  43. Label3->Caption=ptr1[X*3];
  44. r=ptr1[X*3 2];
  45. g=ptr1[X*3 1];
  46. b=ptr1[X*3];
  47. }
  48. }
  49. ///上面是我自己的程式執行沒有問題
  50. ///但是我貼了我在這邊論壇抓到我會用到的濾波程式以後執行就出現了
  51. ///Access violation at address 400BC753 in module 'vcl60.bpl' Read of Address 65785408
  52. ///下面是我從這邊抓到的濾波程式
  53. //---------------------------------------------------------------------------
  54. void __fastcall TForm1::Button4Click(TObject *Sender)
  55. {
  56. Graphics::TBitmap *TheBitmap;
  57. Graphics::TBitmap *Bmp = new Graphics::TBitmap();
  58. Byte *ptr,*mptr,*u1ptr,*u2ptr,*d1ptr,*d2ptr;
  59. int up1,up2,down1,down2,left1,left2,right1,right2;
  60. float Gou;
  61. Bmp->PixelFormat=pf24bit;
  62. Bmp->Assign(Image1->Picture->Bitmap);
  63. for(int y=0;yHeight;y )
  64. {
  65. up1=y-1;
  66. up2=y-2;
  67. down1=y 1;
  68. down2=y 2;
  69. if(up1<0)
  70. up1=Bmp->Height-2;
  71. if(up2<0)
  72. up2=Bmp->Height-2;
  73. if(down1>=Bmp->Height)
  74. down1=0;
  75. if(down2>=Bmp->Height)
  76. down2=0;
  77. ptr =(Byte *)TheBitmap->ScanLine[y];
  78. mptr =(Byte *)Bmp->ScanLine[y];
  79. u1ptr =(Byte *)Bmp->ScanLine[up1];
  80. u2ptr =(Byte *)Bmp->ScanLine[up2];
  81. d1ptr =(Byte *)Bmp->ScanLine[down1];
  82. d2ptr =(Byte *)Bmp->ScanLine[down2];
  83. for(int x=0;xWidth;x )
  84. {
  85. left1=x-1;
  86. left2=x-2;
  87. right1=x 1;
  88. right2=x 2;
  89. if(left2<0)
  90. left2=Bmp->Width-2;
  91. if(right2==Bmp->Width)
  92. right2=0;
  93. Gou=(u1ptr[left2] 4*u1ptr[left1] 7*u1ptr[x] 4*u1ptr[right1] u1ptr[right2]
  94. 4*u2ptr[left2] 16*u2ptr[left1] 26*u2ptr[x] 16*u2ptr[right1] 4*u2ptr[right2]
  95. 7*mptr[left2] 26*mptr[left1] 41*mptr[x] 26*mptr[right1] 7*mptr[right2]
  96. 4*d1ptr[left2] 16*d1ptr[left1] 26*d1ptr[x] 16*d1ptr[right1] 4*d1ptr[right2]
  97. d2ptr[left2] 4*d2ptr[left1] 7*d2ptr[x] 4*d2ptr[right1] d2ptr[right2])/273;
  98. ptr[x]=(Byte)Gou;
  99. }
  100. }
  101. Image1->Picture->Assign(Bmp);
  102. delete Bmp;
  103. }
    執行上沒有問題 可是一點選button4就出現跳出錯誤 可以幫我看看是什麼問題嗎 前輩們
編輯記錄
trent0131 重新編輯於 2008-08-10 11:22:58, 註解 無‧
trent0131 重新編輯於 2008-08-10 11:23:58, 註解 無‧
trent0131 重新編輯於 2008-08-10 11:24:02, 註解 無‧
trent0131 重新編輯於 2008-08-10 11:25:15, 註解 無‧
trent0131 重新編輯於 2008-08-10 11:25:21, 註解 無‧
trent0131 重新編輯於 2008-08-10 11:27:06, 註解 無‧
trent0131 重新編輯於 2008-08-10 11:27:51, 註解 無‧
ikk
尊榮會員


發表:4
回覆:413
積分:768
註冊:2003-06-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-08-11 09:52:42 IP:163.28.xxx.xxx 訂閱
看錯誤訊息, 應該就是使用到宣告的記憶體位址以外的區域...
試著印出各變數值, 應該就可以知道哪裡出問題..
------
FPGA驗證, FPGA開發平台, http://smims.com
系統時間:2024-04-27 10:24:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!