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

如何儲存rgb座標位址

尚未結案
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-22 10:49:54 IP:218.165.xxx.xxx 未訂閱
小弟我現在滑鼠移過圖片可以顯示座標位置...但是該如何儲存此座標位址...??
limeca
中階會員


發表:2
回覆:74
積分:60
註冊:2005-05-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-22 19:14:13 IP:61.230.xxx.xxx 未訂閱
不太懂你的意思... 既然你都可以顯示了...那要存就沒問題啦!! 可否說詳細一點~
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-07-22 22:57:41 IP:218.165.xxx.xxx 未訂閱
我有張大頭照...想把人臉的特徵點座標能記錄下來...我有參考前面大大的範例..可以讓滑鼠移過有顯示座標...但我不會如何把我點過的座標儲存下來..可否指導一下..或有範例可以參考^^
1666362
初階會員


發表:66
回覆:124
積分:43
註冊:2004-07-07

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-07-22 23:51:36 IP:210.192.xxx.xxx 未訂閱
不知道您現在顯示座標的方式是為何?? 您可以用Memo顯示 這樣就可以存檔
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-07-23 00:13:29 IP:220.134.xxx.xxx 未訂閱
我用的程式碼
StatusBar1->Panels->Items[0]->Text="X座標=>" IntToStr(X);
StatusBar1->Panels->Items[1]->Text="Y坐標=>" IntToStr(Y);
Memo顯示 這樣就可以存檔?可不可以給我ㄧ些參考範例...我需要在圖片上能出現以儲存座標的那個特徵點..
limeca
中階會員


發表:2
回覆:74
積分:60
註冊:2005-05-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-07-23 08:29:59 IP:61.230.xxx.xxx 未訂閱
你好~ 先設全域變數 int number=0; int x_buffer[255];//暫設255個 int y_buffer[255];//暫設255個 你可以把它顯示在ListBox裡~~
   char buf[64];
   sprintf(buf,"%d\t%d",X,Y);
   ListBox1->Items->Add(buf);   //加到ListBox裡
   x_buffer[number]=X;
   y_buffer[number]=Y;
   number  ;
再來拉個button寫個存檔的功能
   SaveDialog1->FileName=CurFileName;  
   if(!SaveDialog1->Execute())
    return;
   CurFileName=SaveDialog1->FileName;
   Caption=OrgFormCaption ":" CurFileName;       TStringList *sl=new TStringList();
   char buf[64];       for(int i=0;iAdd(buf);
    }
   sl->SaveToFile(CurFileName);       delete sl;
發表人 - limeca 於 2005/07/23 08:43:54
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-07-23 11:16:51 IP:218.165.xxx.xxx 未訂閱
char buf[64];
   sprintf(buf,"%d\t%d",X,Y);
   ListBox1->Items->Add(buf);   //加到ListBox裡
   x_buffer[number]=X;
   y_buffer[number]=Y;
   number  ;
我run時出現錯誤
[C   Error] Unit1.cpp(455): E2268 Call to undefined function 'sprintf'
  [C   Error] Unit1.cpp(455): E2451 Undefined symbol 'X'
  [C   Error] Unit1.cpp(455): E2451 Undefined symbol 'Y'
請問一下全域變數是要設在所有程式碼的最上面來宣告..還是在ListBox宣告就可以..我還有一點不懂就是這樣能在圖片上留下你點過的紀錄嗎? 麻煩大大指導..謝謝
limeca
中階會員


發表:2
回覆:74
積分:60
註冊:2005-05-11

發送簡訊給我
#8 引用回覆 回覆 發表時間:2005-07-23 13:07:48 IP:61.230.xxx.xxx 未訂閱
那裡的X,Y指的是你程式裡的
StatusBar1->Panels->Items[0]->Text="X座標=>" IntToStr(X);
StatusBar1->Panels->Items[1]->Text="Y坐標=>" IntToStr(Y);
所以你要把那段程式加在你顯示座標的function裡(應該是在你的點選function裡吧) 目的在於要記錄你要儲存的位址 另外你要include 這樣才能用sprintf 全域變數就設在最上面,不是設在某個function裡 圖片上留下你點過的紀錄???你要在圖上標記你點過的位址嗎??? 上述的方法只有儲存功能並顯示位址... 不能讓你在圖片上看到效果
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#9 引用回覆 回覆 發表時間:2005-07-23 15:40:26 IP:218.165.xxx.xxx 未訂閱
limeca你好: 如果說我要把點過的紀錄在圖片上標記起來(譬如:點過的地方留下紅色的一點)呢?有辦法可以這樣做嗎?
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#10 引用回覆 回覆 發表時間:2005-07-23 16:02:22 IP:220.134.xxx.xxx 未訂閱
limeca你好: 我已經可以run了...但是我有個地方不懂..就是位什麼我連點都還沒點就會在listbox裡面跑出所有的數值呢? 我給您看一下我加後的程式碼
#include 
#pragma hdrstop
#include
#include "Unit1.h"
#include
int number=0;
int x_buffer[255];
int y_buffer[255];
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------    void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
        Graphics::TBitmap *TheBitmap;
        TheBitmap=Image1->Picture->Bitmap;            char buf[64];
       sprintf(buf,"%d\t%d",X,Y);
       ListBox1->Items->Add(buf);   
       x_buffer[number]=X;
       y_buffer[number]=Y;
       number  ;            if(TheBitmap->ScanLine[0])
        {
                StatusBar1->Panels->Items[0]->Text="X座標=>" IntToStr(X);
                StatusBar1->Panels->Items[1]->Text="Y坐標=>" IntToStr(Y);
        }            if(Masking)
        {
                TheBitmap->Canvas->Pen->Style=psDash;
                TheBitmap->Canvas->Pen->Mode=pmBlack;
                TheBitmap->Canvas->Brush->Style=bsClear;                    TheBitmap->Canvas->Draw(0,0,OrgBitmap);
                TheBitmap->Canvas->Rectangle(StartX,StartY,X,Y);            }
      if(Pasting)
      {
        TheBitmap->Canvas->Draw(0,0,OrgBitmap);
        TheBitmap->Canvas->Draw(X-StartX,Y-StartY,PasteBitmap);
        TheBitmap->Canvas->Pen->Style=psDash;
        TheBitmap->Canvas->Pen->Mode=pmBlack;
        TheBitmap->Canvas->Brush->Style=bsClear;
        TheBitmap->Canvas->Rectangle(X-StartX,Y-StartY,X-StartX PasteBitmap->Width,
                           Y-StartY PasteBitmap->Height);          }    }
//---------------------------------------------------------------------------        void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
        float ScaleFactor;            if(ComboBox1->Text=="25%")
                ScaleFactor=4.0;
        else if(ComboBox1->Text=="50%")
                ScaleFactor=2.0;
        else if(ComboBox1->Text=="75%")
                ScaleFactor=1.25;
        else if(ComboBox1->Text=="100%")
                ScaleFactor=1.0;
        else if(ComboBox1->Text=="150%")
                ScaleFactor=0.75;
        else if(ComboBox1->Text=="200%")
                ScaleFactor=0.5;
        else
        {
                ScaleFactor=1.0;
                ComboBox1->Text="100%";
        }            Image1->AutoSize=false;
        Image1->Stretch=true;
        Image1->Width=Image1->Picture->Bitmap->Width/ScaleFactor;
        Image1->Height=Image1->Picture->Bitmap->Height/ScaleFactor;        }
//---------------------------------------------------------------------------        void __fastcall TForm1::N12Click(TObject *Sender)
{
        Graphics::TBitmap *TheBitmap, *TempBitmap;
        int Width,Height;
        Byte *ptr1,*ptr2;            TempBitmap= new Graphics::TBitmap();            TheBitmap= Image1->Picture->Bitmap;
        TheBitmap->PixelFormat=pf8bit;            TempBitmap->Assign(TheBitmap);            Width=TheBitmap->Width;
        Height=TheBitmap->Height;            for(int y=0;yScanLine[y];
                ptr2=(Byte*)TheBitmap->ScanLine[y];                    for(int x=0;xAssign(TempBitmap);
        delete TempBitmap;        
}
//---------------------------------------------------------------------------    void __fastcall TForm1::N13Click(TObject *Sender)
{
        Graphics::TBitmap *TheBitmap, *TempBitmap;
        int Width,Height;
        Byte *ptr1,*ptr2;            TempBitmap= new Graphics::TBitmap();            TheBitmap= Image1->Picture->Bitmap;            TempBitmap->Assign(TheBitmap);            Width=TheBitmap->Width;
        Height=TheBitmap->Height;            for(int y=0;yCanvas->Pixels[x][y]=
           TheBitmap->Canvas->Pixels[x][Height-1-y];            TheBitmap->Assign(TempBitmap);
        delete TempBitmap;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::N15Click(TObject *Sender)
{
        Graphics::TBitmap *TheBitmap, *TempBitmap;
        int Width,Height;
        Byte *ptr1,*ptr2;            TempBitmap= new Graphics :: TBitmap();            TheBitmap=Image1->Picture->Bitmap;
        TheBitmap->PixelFormat=pf8bit;            Width=TheBitmap->Width;
        Height=TheBitmap->Height;            TempBitmap->Assign(TheBitmap);            TempBitmap->Width=Height;
        TempBitmap->Height=Width;            for(int y=0;yScanLine[y];
                for(int x=0;xScanLine[Width-1-x];
                        ptr1[y]=ptr2[x];
                }            }            TheBitmap->Assign(TempBitmap);
        delete TempBitmap;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::N16Click(TObject *Sender)
{
          Graphics::TBitmap *TheBitmap, *TempBitmap;
        int Width,Height;
        Byte *ptr1,*ptr2;            TempBitmap= new Graphics :: TBitmap();            TheBitmap=Image1->Picture->Bitmap;
        TheBitmap->PixelFormat=pf8bit;            Width=TheBitmap->Width;
        Height=TheBitmap->Height;            TempBitmap->Assign(TheBitmap);            TempBitmap->Width=Height;
        TempBitmap->Height=Width;            for(int y=0;yScanLine[y];
                for(int x=0;xScanLine[x];
                        ptr1[Height-1-y]=ptr2[x];
                }            }            TheBitmap->Assign(TempBitmap);
        delete TempBitmap;    }
//---------------------------------------------------------------------------        void __fastcall TForm1::Image1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
        Graphics::TBitmap *TheBitmap;            StartX=X;
        StartY=Y;            if(Pasting_Enable)
         {
                Pasting=true; Masking=false;
                Pasting_Enable=false;
         }
        else
        {
                Masking=true; Pasting=false;
                TheBitmap=Image1->Picture->Bitmap;
                TheBitmap->Canvas->Draw(0,0,OrgBitmap);
        }                Masking=true;            TheBitmap=Image1->Picture->Bitmap;
        TheBitmap->Canvas->Draw(0,0,OrgBitmap);        
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
        Graphics::TBitmap *TheBitmap;            if(Pasting)
        {
                TheBitmap=Image1->Picture->Bitmap;
                TheBitmap->Canvas->Draw(0,0,OrgBitmap);
                TheBitmap->Canvas->Draw(X-StartX,Y-StartY,PasteBitmap);
                OrgBitmap->Assign(TheBitmap);
                Pasting=false;
        }                Masking=false;            EndX=X;
        EndY=Y;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::N6Click(TObject *Sender)
{
        Graphics::TBitmap *TheBitmap,*TempBitmap;
        int Width,Height;
        int TFX,TFY,BRX,BRY;
        TRect SrcRect,DestRect;            TheBitmap=Image1->Picture->Bitmap;            TheBitmap->Canvas->Draw(0,0,OrgBitmap);            TempBitmap= new Graphics::TBitmap();            Width=abs(EndX-StartX);
        Height=abs(EndY-StartY);            TFX= min(EndX,StartX); BRX= max(EndX,StartX);
        TFY= min(EndY,StartY); BRY= max(EndY,StartY);           TempBitmap->Width=Width;
        TempBitmap->Height=Height;
        TempBitmap->PixelFormat=pf24bit;
        TempBitmap->Canvas->CopyMode=cmSrcCopy;
        SrcRect=Rect(TFX,TFY,BRX,BRY);
        DestRect=Rect(0,0,Width,Height);
        TempBitmap->Canvas->CopyRect(DestRect,TheBitmap->Canvas,SrcRect);            Clipboard()->Assign(TempBitmap);            TheBitmap->Canvas->Pen->Style=psSolid;
        TheBitmap->Canvas->Pen->Mode=pmWhite;
        TheBitmap->Canvas->Brush->Style=bsSolid;
        TheBitmap->Canvas->Brush->Color=clWhite;
        TheBitmap->Canvas->Rectangle(TFX,TFY,BRX,BRY);            OrgBitmap->Assign(TheBitmap);        }
//---------------------------------------------------------------------------    void __fastcall TForm1::N7Click(TObject *Sender)
{
       Graphics::TBitmap *TheBitmap,*TempBitmap;
       int Width,Height;
       int TFX,TFY,BRX,BRY;
       TRect SrcRect,DestRect;           TheBitmap=Image1->Picture->Bitmap;           TheBitmap->Canvas->Draw(0,0,OrgBitmap);           TempBitmap=new Graphics::TBitmap();           Width=abs(EndX-StartX);
       Height=abs(EndY-StartY);           TFX=min(EndX,StartX); BRX=max(EndX,StartX);
       TFY=min(EndY,StartY); BRY=max(EndY,StartY);           TempBitmap->Width=Width;
       TempBitmap->Height=Height;
       TempBitmap->PixelFormat=pf24bit;
       TempBitmap->Canvas->CopyMode=cmSrcCopy;
       SrcRect=Rect(TFX,TFY,BRX,BRY);
       DestRect=Rect(0,0,Width,Height);           TempBitmap->Canvas->CopyRect(DestRect,TheBitmap->Canvas,SrcRect);           Clipboard()->Assign(TempBitmap);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::N8Click(TObject *Sender)
{
        Graphics::TBitmap *TheBitmap;            TheBitmap=Image1->Picture->Bitmap;            if(Clipboard()->HasFormat(CF_BITMAP))
        {
                PasteBitmap->Assign(Clipboard());                    TheBitmap->Canvas->Draw(0,0,PasteBitmap);                    TheBitmap->Canvas->Pen->Width=2;
                TheBitmap->Canvas->Pen->Mode=pmBlack;
                TheBitmap->Canvas->Brush->Style=bsClear;
         TheBitmap->Canvas->Rectangle(0,0,PasteBitmap->Width,PasteBitmap->Height);
                Pasting_Enable=true;
        }
}
//---------------------------------------------------------------------------     void __fastcall TForm1::Button1Click(TObject *Sender)
{
   Graphics::TBitmap *TheBitmap;
   Byte *ptr;
   int r,g,b;
   int gray;
   int i,j;
   TheBitmap = Image1->Picture->Bitmap;
   for (j=0; jHeight; j  )
   {
      ptr = (Byte *)TheBitmap->ScanLine[j];
      for (i=0; iWidth; i  )
      {
         b = ptr[i*3];
         g = ptr[i*3 1];
         r = ptr[i*3 2];
         gray = 0.299*r 0.587*g 0.114*b;
         if (gray>125)
         gray = 255;
         else
            gray = 0;
         ptr[i*3  ] = (Byte)gray;
         ptr[i*3 1] = (Byte)gray;
         ptr[i*3 2] = (Byte)gray;
      }
   }
   Image1->Picture->Assign(TheBitmap);
}    
limeca
中階會員


發表:2
回覆:74
積分:60
註冊:2005-05-11

發送簡訊給我
#11 引用回覆 回覆 發表時間:2005-07-23 21:45:58 IP:61.230.xxx.xxx 未訂閱
因為你把它寫在MouseMove的這個事件裡了... 所以當你滑鼠移動一下..就記錄一次 如果你想要點選時才有動作... 那就得寫在MouseDown or MouseUp的事件中~
frankh
一般會員


發表:25
回覆:36
積分:12
註冊:2005-05-04

發送簡訊給我
#12 引用回覆 回覆 發表時間:2005-07-23 22:17:22 IP:220.134.xxx.xxx 未訂閱
limeca你好: 如果說我要把點過的紀錄在圖片上標記起來(譬如:點過的地方留下紅色的一點)呢?有辦法可以這樣做嗎?
limeca
中階會員


發表:2
回覆:74
積分:60
註冊:2005-05-11

發送簡訊給我
#13 引用回覆 回覆 發表時間:2005-07-24 10:18:04 IP:61.230.xxx.xxx 未訂閱
有辦法做到.. 你可以試著查看看有沒有畫點的function    我把我目前知道的方法提供給你
   HWND hwnd;
   HDC hdc;
   hwnd=this->Handle;
   hdc=GetDC(hwnd);
   SetPixel(hdc,X Image1->Left , Y Image1->Top ,clRed);
系統時間:2024-04-26 21:21:45
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!