• 主页

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

cokeclassic 2003-01-14 08:05:03

...全文
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)
{
// 根据当前的淡化效果，执行不同的程序
}
{
// 如果每个画刷被使用，当前淡化效果设为None,
// 并关闭timer1，用实心黑色画刷填充图像
if (Progress == BRUSHCOUNT)
{
CurrentEffect = None;
Progress = 0;
Timer1->Enabled = false;
WorkSpaceBitmap->Canvas->Brush = SolidBlackBrush;
WorkSpaceBitmap->Canvas->FillRect(BitmapRect);
}
else
{
// 选择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);
}

{
// 如果每个画刷被使用，当前淡化效果设为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
{
// 选择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);
}
{
// 如果每个画刷被使用，当前淡化效果设为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
{
// 选择Copy模式：copymode cmMergeCopy?DEST = DEST & BRUSH
WorkSpaceBitmap->Canvas->CopyMode=cmMergeCopy;
WorkSpaceBitmap->Canvas->Draw(0,0,WorkSpaceBitmap);
// 选择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);
// 选择Copy模式：copymode cmSrcPaint?
WorkSpaceBitmap->Canvas->CopyMode=cmSrcPaint;
WorkSpaceBitmap->Canvas->Draw(0,0,TempBitmap);
Progress++;
}
// 将内存中的像素绘到屏幕上
PaintBox1->Canvas->Draw(0,0,WorkSpaceBitmap);
}

yuliwe 2003-01-15
{
// 在淡化过程中，静止新的图像淡化
if (CurrentEffect == None)
{
Timer1->Enabled = true; // 打开timer1
Progress = 0; // 设置当前进度
}
}

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

cokeclassic 2003-01-14
Graphics::TBitmap * pBitmap;
pBitmap像素坐标的方法怎么没有啊？
Value是什么？

to 乡下人:

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.

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

GetRValue(RGB(255,5,0));返回255.

GetBValue, GetGValue, GetRValue

Windows SDK/API

1202

C++ Builder Windows SDK/API