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

圖片 pixel 值做 shift 的問題

答題得分者是:dllee
cwshyang
一般會員


發表:9
回覆:10
積分:3
註冊:2003-04-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-06-19 17:36:34 IP:210.68.xxx.xxx 未訂閱
我要將圖片的某一點的值做向左位移 因為我只想取 8 bit 的資料來使用 但 shift 後 所得的值並不我想要的 要怎麼改善呢? 如 24:0001 1000 向左位移後我確得到 1 1000 0000 的值 而不是 1000 0000 我該如何改才能得到正確的值呢???? 請各位大大教我一下..謝謝 ----------我的程式碼----我使用灰階圖片---BCB 5 #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; unsigned char color[1000][1000]; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::N2Click(TObject *Sender) { if(OpenDialog1->Execute()) { Image1->Picture->LoadFromFile(OpenDialog1->FileName); Image1->Width=Image1->Picture->Width; Image1->Height=Image1->Picture->Height; } StatusBar1->Panels->Items[1]->Text=(AnsiString(OpenDialog1->FileName)); for(int w=0;wPicture->Width;w ) for(int h=0;hPicture->Height;h ) color[w][h]=GetGValue(Image1->Canvas->Pixels[w][h]); } //--------------------------------------------------------------------------- void __fastcall TForm1::N9Click(TObject *Sender) { Memo1->Lines->Add("Gray Level:"); for(int w=0;w<2;w ) for(int h=0;h<2;h ) Memo1->Lines->Add(color[w][h]); Memo1->Lines->Add("向左位移 4 bits:"); Memo1->Lines->Add(color[0][0] << 4); Memo1->Lines->Add("向右位移 4 bits:"); Memo1->Lines->Add(color[0][0] >> 4); } //---------------------------------------------------------------------------
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-06-19 17:56:00 IP:61.231.xxx.xxx 未訂閱
引言: 我要將圖片的某一點的值做向左位移 因為我只想取 8 bit 的資料來使用 但 shift 後 所得的值並不我想要的 要怎麼改善呢? 如 24:0001 1000 向左位移後我確得到 1 1000 0000 的值 而不是 1000 0000 我該如何改才能得到正確的值呢???? 請各位大大教我一下..謝謝 ----------我的程式碼----我使用灰階圖片---BCB 5
#include 
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
unsigned char color[1000][1000];
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------    void __fastcall TForm1::N2Click(TObject *Sender)
{
 if(OpenDialog1->Execute())
 {
  Image1->Picture->LoadFromFile(OpenDialog1->FileName);
  Image1->Width=Image1->Picture->Width;
  Image1->Height=Image1->Picture->Height;
 }
 StatusBar1->Panels->Items[1]->Text=(AnsiString(OpenDialog1->FileName));     for(int w=0;wPicture->Width;w  )
  for(int h=0;hPicture->Height;h  )
   color[w][h]=GetGValue(Image1->Canvas->Pixels[w][h]);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::N9Click(TObject *Sender)
{
 Memo1->Lines->Add("Gray Level:");
 for(int w=0;w<2;w  )
  for(int h=0;h<2;h  )
   Memo1->Lines->Add(color[w][h]);     Memo1->Lines->Add("向左位移 4 bits:");
 Memo1->Lines->Add(Byte(color[0][0] << 4));     Memo1->Lines->Add("向右位移 4 bits:");
 Memo1->Lines->Add(Byte(color[0][0] >> 4));
}
//---------------------------------------------------------------------------
沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
cwshyang
一般會員


發表:9
回覆:10
積分:3
註冊:2003-04-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-06-19 18:05:55 IP:210.68.xxx.xxx 未訂閱
引言:
引言: 我要將圖片的某一點的值做向左位移 因為我只想取 8 bit 的資料來使用 但 shift 後 所得的值並不我想要的 要怎麼改善呢? 如 24:0001 1000 向左位移後我確得到 1 1000 0000 的值 而不是 1000 0000 我該如何改才能得到正確的值呢???? 請各位大大教我一下..謝謝 ----------我的程式碼----我使用灰階圖片---BCB 5
#include 
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
unsigned char color[1000][1000];
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------    void __fastcall TForm1::N2Click(TObject *Sender)
{
 if(OpenDialog1->Execute())
 {
  Image1->Picture->LoadFromFile(OpenDialog1->FileName);
  Image1->Width=Image1->Picture->Width;
  Image1->Height=Image1->Picture->Height;
 }
 StatusBar1->Panels->Items[1]->Text=(AnsiString(OpenDialog1->FileName));     for(int w=0;wPicture->Width;w  )
  for(int h=0;hPicture->Height;h  )
   color[w][h]=GetGValue(Image1->Canvas->Pixels[w][h]);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::N9Click(TObject *Sender)
{
 Memo1->Lines->Add("Gray Level:");
 for(int w=0;w<2;w  )
  for(int h=0;h<2;h  )
   Memo1->Lines->Add(color[w][h]);     Memo1->Lines->Add("向左位移 4 bits:");
 Memo1->Lines->Add(Byte(color[0][0] << 4));     Memo1->Lines->Add("向右位移 4 bits:");
 Memo1->Lines->Add(Byte(color[0][0] >> 4));
}
//---------------------------------------------------------------------------
沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
謝謝 第一次 po 文章問問題 這麼快就有答案了~~~ 感謝你喔~~~~
系統時間:2024-05-05 22:20:50
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!