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

RGB是這樣抓嗎?

尚未結案
holyduck
一般會員


發表:11
回覆:14
積分:5
註冊:2005-06-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-15 03:59:21 IP:218.165.xxx.xxx 未訂閱
我開了一張bmp灰階圖之後用
Byte *R,*G,*B;
int* bmp2array(Graphics::TBitmap *bmp,int *wp,int *hp)
{
int i,j;
int *f0,*f;
int w,h;
Byte *ptr;
w=bmp->Width;
h=bmp->Height;    *wp=w;
*hp=h;
f0=new int[w*h];
f=f0;
R=new Byte[w*h];
G=new Byte[w*h];
B=new Byte[w*h];
for(i=0;iScanLine[i];       for(j=0;jScanLine[i];
    int index=0;
    for(int j=0; j
抓灰階圖的索引值跟RGB值
請問RGB的部份對不對?
因為我開的是灰階的圖
照理說RGB的值應該是一樣的才對
可是我怎麼樣都看不懂他的排列
我是這樣showRGB值的
 String b="";
 String g="";
 String r="";
 Form1->memRGB->Clear();
 for(int i=0;imemRGB->Lines->Add(b);
     Form1->memRGB->Lines->Add(g);
     Form1->memRGB->Lines->Add(r);
     b="";
     g="";
     r="";     }
cashyy
高階會員


發表:117
回覆:322
積分:212
註冊:2004-04-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-15 10:59:53 IP:211.74.xxx.xxx 未訂閱
您好! 小弟是用下面方法取RGB的! 如果要source code的話,可以參考下面文章: http://delphi.ktop.com.tw/topic.php?topic_id=65724
//.h
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include <Forms.hpp>
#include 
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:        // IDE-managed Components
    TImage *Image1;
    TStaticText *StaticText1;
    void __fastcall Image1MouseMove(TObject *Sender, TShiftState Shift,
          int X, int Y);
private:        // User declarations
public:                // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif    //.cpp
//---------------------------------------------------------------------------
#include 
#pragma hdrstop    #include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
  //取得Form1的DC
  HDC hdc = ::GetDC(Handle);
  //取得滑鼠位置的圖素色彩
  COLORREF pcolor = ::GetPixel( hdc, X, Y );
  //逐一用巨集取出RGB色彩值
  unsigned int r = GetRValue(pcolor);
  unsigned int g = GetGValue(pcolor);
  unsigned int b = GetBValue(pcolor);
  //將結果即時顯示在Form1標題文字中
  Caption ="滑鼠位置:X = " AnsiString(X) " ,Y =" AnsiString(Y) 
         " ,圖素色彩:R:" AnsiString(r) "_G:" AnsiString(g) 
         "_B:" AnsiString(b);
  //釋放Form1的DC handle
  ReleaseDC(0,hdc);
}
//---------------------------------------------------------------------------
發表人 - cashyy 於 2005/07/15 11:03:00
holyduck
一般會員


發表:11
回覆:14
積分:5
註冊:2005-06-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-07-15 23:55:26 IP:218.165.xxx.xxx 未訂閱
抱歉喔~~ 這應該不是我要的~~ 我是要開一張bmp的圖 然後取出每點的RGB值
KENI_LIN
中階會員


發表:86
回覆:267
積分:90
註冊:2004-05-31

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-07-16 18:54:42 IP:220.228.xxx.xxx 未訂閱
引言: 抓灰階圖的索引值跟RGB值 請問RGB的部份對不對? 因為我開的是灰階的圖 照理說RGB的值應該是一樣的才對 可是我怎麼樣都看不懂他的排列 我是這樣showRGB值的
影像處理方法有很多種,所以選自己最熟悉的語法就可以了; 建議你先找出bmp圖的每一點(X,Y)座標的RGB值是多少 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=57639 在用for迴圈方式把你要的範圍取出來,看看是不是對的!
 
//由(x1,y1)和(x2,y2)就可以組成矩形範圍--------------------
ss1="";
for(int i=x1; i<=x2; i  )
         {
          for(int j=y1; j<=y2; j  )
          {
           aaa = int(Image1->Canvas->Pixels[i][j]);
           rr = char(aaa); //讀取Red值
           
           s1=IntToStr(rr); //將數值存入字串
           ss1=ss1 s1 " ,";         
          };
         };
         
         Memo1->Lines->Add(ss1 "," s "矩陣" tt);
         ss1="";
//---------------------------------------------------------
寒窗苦讀十年書;只待今朝狀元時!~~ ︵ / / ︵ ( ∩ ∩ ) ○ ︶ ○ Keni Lin
------
Keni Lin
系統時間:2024-05-08 2:20:25
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!