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

濾波程式錯誤

尚未結案
trent0131
一般會員


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

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-08-06 14:55:29 IP:123.194.xxx.xxx 訂閱

[code cpp]
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
if (OpenPictureDialog1->Execute())
{
Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
double r,g,b;
int height,width;
Graphics::TBitmap *TheBitMap;
Byte *ptr1;
TheBitMap=Image1->Picture->Bitmap;
height=Image1->Picture->Height;
width=Image1->Picture->Width;
//TheBitMap->PixelFormat=pf8bit;
if(Y {
ptr1=(Byte*)Image1->Picture->Bitmap->ScanLine[Y];
Label1->Caption=ptr1[X*3 2];
Label2->Caption=ptr1[X*3 1];
Label3->Caption=ptr1[X*3];
r=ptr1[X*3 2];
g=ptr1[X*3 1];
b=ptr1[X*3];

}
}
///上面是我自己的程式執行沒有問題
///但是我貼了我在這邊論壇抓到我會用到的濾波程式以後執行就出現了
///Access violation at address 400BC753 in module 'vcl60.bpl' Read of Address 65785408

///下面是我從這邊抓到的濾波程式
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap;
Graphics::TBitmap *Bmp = new Graphics::TBitmap();
Byte *ptr,*mptr,*u1ptr,*u2ptr,*d1ptr,*d2ptr;
int up1,up2,down1,down2,left1,left2,right1,right2;
float Gou;
Bmp->PixelFormat=pf24bit;
Bmp->Assign(Image1->Picture->Bitmap);
for(int y=0;yHeight;y )
{
up1=y-1;
up2=y-2;
down1=y 1;
down2=y 2;
if(up1<0)
up1=Bmp->Height-2;
if(up2<0)
up2=Bmp->Height-2;
if(down1>=Bmp->Height)
down1=0;
if(down2>=Bmp->Height)
down2=0;
ptr =(Byte *)TheBitmap->ScanLine[y];
mptr =(Byte *)Bmp->ScanLine[y];
u1ptr =(Byte *)Bmp->ScanLine[up1];
u2ptr =(Byte *)Bmp->ScanLine[up2];
d1ptr =(Byte *)Bmp->ScanLine[down1];
d2ptr =(Byte *)Bmp->ScanLine[down2];
for(int x=0;xWidth;x )
{
left1=x-1;
left2=x-2;
right1=x 1;
right2=x 2;
if(left2<0)
left2=Bmp->Width-2;
if(right2==Bmp->Width)
right2=0;
Gou=(u1ptr[left2] 4*u1ptr[left1] 7*u1ptr[x] 4*u1ptr[right1] u1ptr[right2]
4*u2ptr[left2] 16*u2ptr[left1] 26*u2ptr[x] 16*u2ptr[right1] 4*u2ptr[right2]
7*mptr[left2] 26*mptr[left1] 41*mptr[x] 26*mptr[right1] 7*mptr[right2]
4*d1ptr[left2] 16*d1ptr[left1] 26*d1ptr[x] 16*d1ptr[right1] 4*d1ptr[right2]
d2ptr[left2] 4*d2ptr[left1] 7*d2ptr[x] 4*d2ptr[right1] d2ptr[right2])/273;
ptr[x]=(Byte)Gou;
}
}
Image1->Picture->Assign(Bmp);
delete Bmp;
}

//---------------------------------------------------------------------------

[/code]
對不起我還很生疏 也許問的問題很菜 但是錯誤不知道該從哪改起 可以請大大幫幫忙嗎 謝謝
編輯記錄
trent0131 重新編輯於 2008-08-06 14:58:47, 註解 無‧
trent0131 重新編輯於 2008-08-06 15:00:16, 註解 無‧
系統時間:2024-04-27 12:08:05
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!