deh3215
一般會員
發表:3 回覆:4 積分:1 註冊:2005-10-22
發送簡訊給我
|
//--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
OrgBitmap= new Graphics::TBitmap();//這裡已經宣告,但COMPILE會出現
Undefined OrgBitmap的句子...
}
//-------------------------------------------------------------------
void __fastcall TForm1::N2K1Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap,*TempBitmap;
Byte *ptr, *tptr;
double sum;
unsigned int red,green,blue;
LOGPALETTE MyPalette;
PALETTEENTRY pal[1];
HPALETTE MyPaletteHandle;
//----------------------
TheBitmap=Image1->Picture->Bitmap;
//----------------------
TempBitmap=new Graphics::TBitmap();
TempBitmap->Width=TheBitmap->Width;
TempBitmap->Height=TheBitmap->Height;
TempBitmap->PixelFormat=pf8bit;
//----------------------
MyPalette.palVersion=0x300;
MyPalette.palNumEntries=256;
MyPaletteHandle=CreatePalette(&MyPalette);
for(int i=0;i<256;i )
{
pal[0].peRed=i;
pal[0].peGreen=i;
pal[0].peBlue=i;
SetPaletteEntries(MyPaletteHandle,i,1,pal);
}
TempBitmap->Palette=MyPaletteHandle;
//--------------------------------
for(int y=0;yHeight;y )
{
ptr=(Byte*)TheBitmap->ScanLine[y];
tptr=(Byte*)TempBitmap->ScanLine[y];
for(int x=0;xWidth;x )
{
GetPaletteEntries(TheBitmap->Palette,ptr[x],1,pal);
red=pal[0].peRed;green=pal[0].peGreen;blue=pal[0].peBlue;
sum=red*0.299 green*0.587 blue*0.114;
if(sum>255)
sum=255;
if(sum<0)
sum=0;
tptr[x]=(Byte)sum;
}
}
//-----------------------
TheBitmap->Assign(TempBitmap);
Repaint();
OrgBitmap->Assign(TheBitmap);
delete TempBitmap;
}
上述這段程式碼是把彩色的影像轉成灰階,那麼應該如何修改使得灰階變成多層次的呢?如2 level,4 level,8level...等,還有一個問題已經在前面宣告了Orgbitmap,為何compile還會出現Undefined Orgbitmap.呢....煩請各位幫忙解答..3Q
|
taishyang
站務副站長
發表:377 回覆:5490 積分:4563 註冊:2002-10-08
發送簡訊給我
|
您好: PO程式碼的方式與版規說明請參考下面連結,煩請修改謝謝您的配合
>
|
husser123
一般會員
發表:14 回覆:10 積分:4 註冊:2005-04-17
發送簡訊給我
|
引言:
//--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Graphics::TBitmap *OrgBitmap= new Graphics::TBitmap();//這 裡已經宣告,但COMPILE會出現Undefined OrgBitmap的句子...
}
//-------------------------------------------------------------------
void __fastcall TForm1::N2K1Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap,*TempBitmap;
Byte *ptr, *tptr;
double sum;
unsigned int red,green,blue;
LOGPALETTE MyPalette;
PALETTEENTRY pal[1];
HPALETTE MyPaletteHandle;
//----------------------
TheBitmap=Image1->Picture->Bitmap;
//----------------------
TempBitmap=new Graphics::TBitmap();
TempBitmap->Width=TheBitmap->Width;
TempBitmap->Height=TheBitmap->Height;
TempBitmap->PixelFormat=pf8bit;
//----------------------
MyPalette.palVersion=0x300;
MyPalette.palNumEntries=256;
MyPaletteHandle=CreatePalette(&MyPalette);
for(int i=0;i<256;i )
{
pal[0].peRed=i;
pal[0].peGreen=i;
pal[0].peBlue=i;
SetPaletteEntries(MyPaletteHandle,i,1,pal);
}
TempBitmap->Palette=MyPaletteHandle;
//--------------------------------
for(int y=0;yHeight;y )
{
ptr=(Byte*)TheBitmap->ScanLine[y];
tptr=(Byte*)TempBitmap->ScanLine[y];
for(int x=0;xWidth;x )
{
GetPaletteEntries(TheBitmap->Palette,ptr[x],1,pal);
red=pal[0].peRed;green=pal[0].peGreen;blue=pal[0].peBlue;
sum=red*0.299 green*0.587 blue*0.114;
if(sum>255)
sum=255;
if(sum<0)
sum=0;
// 以128二值化
if(sum>=128)
sum=255;
else
sum=0;
tptr[x]=(Byte)sum;
}
}
//-----------------------
TheBitmap->Assign(TempBitmap);
Repaint();
OrgBitmap->Assign(TheBitmap);
delete TempBitmap;
}
上述這段程式碼是把彩色的影像轉成灰階,那麼應該如何修改使得灰階變成多層次的呢?如2 level,4 level,8level...等,還有一個問題已經在前面宣告了Orgbitmap,為何compile還會出現Undefined Orgbitmap.呢....煩請各位幫忙解答..3Q
至於2階4階...,if多用幾個吧!
|
deh3215
一般會員
發表:3 回覆:4 積分:1 註冊:2005-10-22
發送簡訊給我
|
首先感謝husser123兄的回覆,多層次的灰階部分應該沒問題了,不過OrgBitmap的部分還是怪怪的...另外對發表新主題的部分,小第下次會改進,請版主海涵.
#include
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Graphics::TBitmap *OrgBitmap= new Graphics::TBitmap();
}
.
.
略
.
.
//-------------------------------------------------------------------
void __fastcall TForm1::N2K1Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap,*TempBitmap,*OrgBitmap;//紅色部分是小弟自己加的
Byte *ptr, *tptr;
double sum;
unsigned int red,green,blue;
LOGPALETTE MyPalette;
PALETTEENTRY pal[1];
HPALETTE MyPaletteHandle;
//----------------------
TheBitmap=Image1->Picture->Bitmap;
//----------------------
TempBitmap=new Graphics::TBitmap();
TempBitmap->Width=TheBitmap->Width;
TempBitmap->Height=TheBitmap->Height;
TempBitmap->PixelFormat=pf8bit;
//----------------------
MyPalette.palVersion=0x300;
MyPalette.palNumEntries=256;
MyPaletteHandle=CreatePalette(&MyPalette);
for(int i=0;i<256;i )
{
pal[0].peRed=i;
pal[0].peGreen=i;
pal[0].peBlue=i;
SetPaletteEntries(MyPaletteHandle,i,1,pal);
}
TempBitmap->Palette=MyPaletteHandle;
//--------------------------------
for(int y=0;yHeight;y )
{
ptr=(Byte*)TheBitmap->ScanLine[y];
tptr=(Byte*)TempBitmap->ScanLine[y];
for(int x=0;xWidth;x )
{
GetPaletteEntries(TheBitmap->Palette,ptr[x],1,pal);
red=pal[0].peRed;green=pal[0].peGreen;blue=pal[0].peBlue;
sum=red*0.299 green*0.587 blue*0.114;
if(sum>255)
sum=255;
if(sum<0)
sum=0;
tptr[x]=(Byte)sum;
}
}
//-----------------------
TheBitmap->Assign(TempBitmap);
Repaint();
OrgBitmap->Assign(TheBitmap);
delete TempBitmap;
}
compille會出現[C Warning] Unit1.cpp(16): W8004 'OrgBitmap' is assigned a value that is never used....
不知道哪裡出了問題??
|
taishyang
站務副站長
發表:377 回覆:5490 積分:4563 註冊:2002-10-08
發送簡訊給我
|
再次提醒您,若不遵守恕刪除 PO程式碼的方式與版規說明請參考下面連結,煩請修改謝謝您的配合
>
|
husser123
一般會員
發表:14 回覆:10 積分:4 註冊:2005-04-17
發送簡訊給我
|
1.compille出現[C Warning],還是可以run 2.哪裡出問題? Unit1.cpp(16): W8004 'OrgBitmap' is assigned a value that is never used....
它不是很清楚的說明了嗎?
|
deh3215
一般會員
發表:3 回覆:4 積分:1 註冊:2005-10-22
發送簡訊給我
|
這個訊息似乎是指讀取到不該讀的記憶體區塊....灰階的效果是出來了..
不過這個問題始終無法解決..小弟再試試看好了..多謝husser123的回覆..
|