cwshyang
一般會員
發表:9 回覆:10 積分:3 註冊:2003-04-10
發送簡訊給我
|
我要將圖片的某一點的值做向左位移
因為我只想取 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
發送簡訊給我
|
引言:
我要將圖片的某一點的值做向左位移
因為我只想取 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
發送簡訊給我
|
引言:
引言:
我要將圖片的某一點的值做向左位移
因為我只想取 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 文章問問題
這麼快就有答案了~~~
感謝你喔~~~~
|