有關出現Access violation at address 的問題 |
答題得分者是:dominicx
|
qqpop
一般會員 發表:2 回覆:0 積分:0 註冊:2008-12-27 發送簡訊給我 |
為何為出現Access violation at address 這樣的問題呢?
我用的是512*512的圖片 而有問題的地方出現在 int RValue=255-ptr[x*3 2]; 這裡 有人可以幫我解答嗎? 謝謝 ================引 用http://delphi.ktop.com.tw/board.php?cid=31&fid=79&tid=40159 文 章===程式的底片部份 [code cpp] #include #include <math.h><br />#pragma hdrstop #include "ImageProcess.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { if (OpenPictureDialog1->Execute()) Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName); } //----------------------------------------------- void __fastcall TForm1::Button13Click(TObject *Sender) { if (Image1->Picture->Bitmap->Empty==true) ShowMessage("請載入圖檔!!"); Graphics::TBitmap* BMP=new Graphics::TBitmap(); BMP->Assign(Image1->Picture->Bitmap ); Byte* ptr=NULL; for (int y=0;y { ptr=(Byte*)BMP->ScanLine[y]; for (int x=0;x { int RValue=255-ptr[x*3 2]; int GValue=255-ptr[x*3 1]; int BValue=255-ptr[x*3]; ptr[x*3 2]=RValue; ptr[x*3 1]=GValue; ptr[x*3] =BValue; } } Image2->Picture->Assign(BMP); delete BMP; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { if (Image2->Picture->Bitmap->Empty==true) ShowMessage("沒有可以存檔的畫面喔!!"); else if (SavePictureDialog1->Execute()) Image2->Picture->SaveToFile(SavePictureDialog1->FileName); } //-------------------------------------------------- [/code] 編輯記錄
qqpop 重新編輯於 2009-07-01 17:18:33, 註解 無‧
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
dominicx
一般會員 發表:6 回覆:10 積分:13 註冊:2007-05-07 發送簡訊給我 |
[code cpp] for (int y=0;y { ptr=(Byte*)BMP->ScanLine[y]; for (int x=0;x { int RValue=255-ptr[x*3 2]; int GValue=255-ptr[x*3 1]; int BValue=255-ptr[x*3]; ptr[x*3 2]=RValue; ptr[x*3 1]=GValue; ptr[x*3] =BValue; } } [/code] 你先前提到圖案的大小是512x512 在ptr=(Byte*)BMP->ScanLine[y]; 這行表示你的ptr指標指到了圖片中Line[y]的位置 長度為512 (因為寬是512) 你在ptr[x*3 2] 中的x最大可以跑到512 而512*3 2遠超過於你指標所指的位置的長度512 你可能要回去重新檢查一下邏輯
編輯記錄
dominicx 重新編輯於 2009-08-10 20:40:20, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |