如何获得像素 的R,G,B对应的三个值??

cokeclassic 2003-01-14 08:05:03
如何获得像素 的R,G,B对应的三个值??
...全文
34 点赞 收藏 20
写回复
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
penu 2003-01-15
唤,来太晚了,大家都说完了。没得说的了——
回复
cokeclassic 2003-01-15
请帮我看看,下面的图片淡出代码,有什么问题!
int r,g,b;
Graphics::TBitmap * bitmap=new Graphics::TBitmap();
bitmap->PixelFormat=pf24bit;
bitmap->Assign(Image1->Picture->Bitmap);
for(int i=0;i<256;i++)
{
for(int j=0;j<bitmap->Height;j++)
{
for(int k=0;k<bitmap->Width;k++)
{
DWORD value=bitmap->Canvas->Pixels[j][k];
r = (value>>16) & 0xff;
g = (value>>8 ) & 0xff;
b = (value) & 0xff;
if(r>0) r--;
if(g>0) g--;
if(b>0) b--;
bitmap->Canvas->Pixels[j][k]=TColor(RGB(r,g,b));

}

}
Image1->Canvas->Draw(0,0,bitmap);
Application->ProcessMessages();

}
分不够再加啊,为什么图片的右边有一小部分,不会变啊?
你们的谈出代码是怎么样啊?
回复
cokeclassic 2003-01-15
请帮我看看,下面的图片淡出代码,有什么问题!
int r,g,b;
Graphics::TBitmap * bitmap=new Graphics::TBitmap();
bitmap->PixelFormat=pf24bit;
bitmap->Assign(Image1->Picture->Bitmap);
for(int i=0;i<256;i++)
{
for(int j=0;j<bitmap->Height;j++)
{
for(int k=0;k<bitmap->Width;k++)
{
DWORD value=bitmap->Canvas->Pixels[j][k];
r = (value>>16) & 0xff;
g = (value>>8 ) & 0xff;
b = (value) & 0xff;
if(r>0) r--;
if(g>0) g--;
if(b>0) b--;
bitmap->Canvas->Pixels[j][k]=TColor(RGB(r,g,b));

}

}
Image1->Canvas->Draw(0,0,bitmap);
Application->ProcessMessages();

}
回复
halibut 2003-01-15
to RomanticProgrammer(兰企鹅||南极俺最帅) :

抢分是一个目的,另外也是学习呀!
回复
cokeclassic 2003-01-15
请帮我看看,下面的图片淡出代码,有什么问题!
int r,g,b;
Graphics::TBitmap * bitmap=new Graphics::TBitmap();
bitmap->PixelFormat=pf24bit;
bitmap->Assign(Image1->Picture->Bitmap);
for(int i=0;i<256;i++)
{
for(int j=0;j<bitmap->Height;j++)
{
for(int k=0;k<bitmap->Width;k++)
{
DWORD value=bitmap->Canvas->Pixels[j][k];
r = (value>>16) & 0xff;
g = (value>>8 ) & 0xff;
b = (value) & 0xff;
if(r>0) r--;
if(g>0) g--;
if(b>0) b--;
bitmap->Canvas->Pixels[j][k]=TColor(RGB(r,g,b));

}

}
Image1->Canvas->Draw(0,0,bitmap);
Application->ProcessMessages();

}
回复
yuliwe 2003-01-15
void __fastcall TMainForm::Timer1Timer(TObject *Sender)
{
// 根据当前的淡化效果,执行不同的程序
if(CurrentEffect == FadeToBlack)
ProcessFadeToBlackStep();
else if(CurrentEffect == FadeFromBlack)
ProcessFadeFromBlackStep();
else if(CurrentEffect == FadeToImage)
ProcessFadeToImageStep();
}
void TMainForm::ProcessFadeToBlackStep(void)
{
// 如果每个画刷被使用,当前淡化效果设为None,
// 并关闭timer1,用实心黑色画刷填充图像
if (Progress == BRUSHCOUNT)
{
CurrentEffect = None;
Progress = 0;
Timer1->Enabled = false;
WorkSpaceBitmap->Canvas->Brush = SolidBlackBrush;
WorkSpaceBitmap->Canvas->FillRect(BitmapRect);
}
else
// 否则,从positivemasks中选择一个画刷绘画图像
{
WorkSpaceBitmap->Canvas->Brush = PositiveMasks[Progress];
// 选择Copy模式:copymode cmMergeCopy ?
//DEST = BRUSH & DEST, no SOURCE bitmap
WorkSpaceBitmap->Canvas->CopyMode=cmMergeCopy;
//用模式画刷重画内存位图WorkSpaceBitmap中
WorkSpaceBitmap->Canvas->Draw(0,0,WorkSpaceBitmap);
Progress++;
}
// 将内存中的像素绘到屏幕上
PaintBox1->Canvas->Draw(0,0,WorkSpaceBitmap);
}

void TMainForm::ProcessFadeFromBlackStep(void)
{
// 如果每个画刷被使用,当前淡化效果设为None,
// 并关闭timer1,将显示全部的图像
if (Progress == BRUSHCOUNT)
{
CurrentEffect = None;
Progress = 0;
Timer1->Enabled = false;
WorkSpaceBitmap->Canvas->CopyMode=cmSrcCopy;
if(CurrentDrawing == Pictrue1)
WorkSpaceBitmap->Canvas->Draw(0,0,Pictrue1Bitmap);
else
WorkSpaceBitmap->Canvas->Draw(0,0,Pictrue2Bitmap);
}
else
{
// 否则,从Negativemasks中选择一个画刷绘画图像
WorkSpaceBitmap->Canvas->Brush =NegativeMasks[Progress];
// 选择Copy模式:copymode cmMergeCopy?DEST = SRC & BRUSH
WorkSpaceBitmap->Canvas->CopyMode=cmMergeCopy;
if(CurrentDrawing == Pictrue1)
WorkSpaceBitmap->Canvas->Draw(0,0,Pictrue1Bitmap);
else
WorkSpaceBitmap->Canvas->Draw(0,0,Pictrue2Bitmap);
Progress++;
}
// 将内存中的像素绘到屏幕上
PaintBox1->Canvas->Draw(0,0,WorkSpaceBitmap);
}
void TMainForm::ProcessFadeToImageStep(void)
{
// 如果每个画刷被使用,当前淡化效果设为None,
// 并关闭timer1,将显示全部的图像
if (Progress == BRUSHCOUNT)
{
CurrentEffect = None;
Progress = 0;
Timer1->Enabled = false;
WorkSpaceBitmap->Canvas->CopyMode=cmSrcCopy;
if(CurrentDrawing == Pictrue1)
{
WorkSpaceBitmap->Canvas->Draw(0,0,Pictrue2Bitmap);
CurrentDrawing = Pictrue2;
}
else
{
WorkSpaceBitmap->Canvas->Draw(0,0,Pictrue1Bitmap);
CurrentDrawing = Pictrue1;
}
}
else
// 否则,从Positivemasks中选择一个画刷绘画图像
{
WorkSpaceBitmap->Canvas->Brush = PositiveMasks[Progress];
// 选择Copy模式:copymode cmMergeCopy?DEST = DEST & BRUSH
WorkSpaceBitmap->Canvas->CopyMode=cmMergeCopy;
WorkSpaceBitmap->Canvas->Draw(0,0,WorkSpaceBitmap);
//从NegativeMasks中选择一个画刷绘画图像
TempBitmap->Canvas->Brush = NegativeMasks[Progress];
// 选择Copy模式:copymode cmMergeCopy?DEST = SRC & BRUSH
TempBitmap->Canvas->CopyMode=cmMergeCopy;
if(CurrentDrawing == Pictrue1)
TempBitmap->Canvas->Draw(0,0,Pictrue2Bitmap);
else
TempBitmap->Canvas->Draw(0,0,Pictrue1Bitmap);
//从PositiveMasks中选择一个画刷绘画图像
WorkSpaceBitmap->Canvas->Brush = PositiveMasks[Progress];
// 选择Copy模式:copymode cmSrcPaint?
WorkSpaceBitmap->Canvas->CopyMode=cmSrcPaint;
WorkSpaceBitmap->Canvas->Draw(0,0,TempBitmap);
Progress++;
}
// 将内存中的像素绘到屏幕上
PaintBox1->Canvas->Draw(0,0,WorkSpaceBitmap);
}
回复
yuliwe 2003-01-15
void __fastcall TMainForm::FadeFromBlackButtonClick(TObject *Sender)
{
// 在淡化过程中,静止新的图像淡化
if (CurrentEffect == None)
{
FadeFromBlackButton ->Enabled = false; // 静止FadeFromBlackButton按钮
FadeToBlackButton ->Enabled = true; // 允许FadeToBlackButton按钮
Timer1->Enabled = true; // 打开timer1
CurrentEffect = FadeFromBlack; // 设置当前淡化效果
Progress = 0; // 设置当前进度
ProcessFadeFromBlackStep(); // 开始执行淡化程序
}
}
回复
yuliwe 2003-01-15
是啊是啊!不过我有个图片淡出的例子,你可以参考一下了
回复
zywx 2003-01-14
color
0x55 55 55
__ __ __
| | |
R G B


知道上面的关系自己算吧
回复
Bitmap1->Canvas->Pixels[i][j];//取得象素点的RGB.
回复
cdws222 2003-01-14
大家全说对了
回复
wangxiangsjz 2003-01-14
TColor C=RGB(R,G,B);
回复
cokeclassic 2003-01-14
怎么通过变量分别给R,G,B赋值呢?
回复
cokeclassic 2003-01-14
Graphics::TBitmap * pBitmap;
pBitmap像素坐标的方法怎么没有啊?
Value是什么?
回复
to 乡下人:
就20分,你还要跟我抢....呜呜呜~~~~ :P
回复
乡下人的方法也不错...呵呵.
回复
halibut 2003-01-14
r = (value>>16) & 0xff;
g = (value>>8 ) & 0xff;
b = (value) & 0xff;
回复
The GetRValue macro retrieves an intensity value for the red component of a 32-bit red, green, blue (RGB) value.

BYTE GetRValue(
DWORD rgb // 32-bit RGB value
);

Parameters
rgb
Specifies an RGB color value.
Return Values
The return value is the intensity of the red component of the specified RGB color.

Remarks
The intensity value is in the range 0 through 255.

The GetRValue macro is defined as follows:

#define GetRValue(rgb) ((BYTE) (rgb))

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in wingdi.h.

See Also
Colors Overview, Color Macros, GetBValue, GetGValue, PALETTEINDEX, PALETTERGB, RGB

回复
比如
GetRValue(RGB(255,5,0));返回255.
回复
GetBValue, GetGValue, GetRValue
回复
发动态
发帖子
Windows SDK/API
创建于2007-08-02

1202

社区成员

C++ Builder Windows SDK/API
申请成为版主
社区公告
暂无公告