请问如何改变一个图片的某个颜色的分量?(100分)

  • 主题发起人 主题发起人 薄荷
  • 开始时间 开始时间

薄荷

Unregistered / Unconfirmed
GUEST, unregistred user!
我有个图片,现在想改变他的洋红($00E0A0E0)分量,请问如何做?

具体的是,我要把这个图片的cmyk的每个分量都可以调整,rgb模式的我会。
 
用1stClass控件中的fcimager控件!
 
To oldsheep35
老兄,他是改某种颜色呢,不是用TransparentColor搞透明之类的,
>> 我要把这个图片的cmyk的每个分量都可以调整,rgb模式的我会。
你这句是什么意思呀?????
呵呵~~~~~~~~~~~~~~~~~~
 
to NetSoft:
CMYK是指用 洋红、青、黄和黑 四种颜色的混和来表示颜色,我现在就是想增加或者减少
其中某种分量比如洋红的比例,
 
你会Rgb模式的,
看你的这个 CMYK与 RGB 或 Delphi的颜色有什么联系不就得了???
说真的没有接触过CMYK,
我认为Delphi的颜色表示就很特别了,
你来个CMYK,我真的晕啦!!!
给点他的资料怎么样???
如怎么表示白色、黑色、红色、绿色什么的??
呵呵~~~~~~~~~~
 
我找到一些这样的资料,你看看对你有没有用吧
改变图象的对比度、亮度、饱和度
宋体 // Bitmap.ScanLine[X] 可以获取图像象素的内存地址,24Bits的Bitmap的每一象
// 素是以三原色RGB的次序存放的,改变RGB的值就可调节Bitmap的色彩.
// R, G, B: -255~255
procedure RGB(var Bmp: TBitmap; R, G, B: Integer);
var
X, Y: Integer;
I: Byte;
ColorTable: array[0..255] of TRGBColor;
pRGB: PRGBColor;
begin
for I := 0 to 255 do
begin
ColorTable.R := Byte(I + R);
ColorTable.G := Byte(I + G);
ColorTable.B := Byte(I + B);
end;

for Y := 0 to Bmp.Height - 1 do
begin
pRGB := Bmp.ScanLine[Y];
for X := 0 to Bmp.Width - 1 do
begin
pRGB.R := ColorTable[pRGB.R].R;
pRGB.G := ColorTable[pRGB.G].G;
pRGB.B := ColorTable[pRGB.B].B;
end;
Inc(pRGB);
end;
end;

// 改变图像的亮度,也只需调用RGB(Bmp, X, X, X)改变三原色.
// 调节Bitmap的对比度
// 应用公式: 新颜色值 = (旧颜色值 - 128) * 系数 + 128
procedure Contrast(var Bmp: TBitmap; Amount: Integer);
// Amount: -255~255
var
X, Y: Integer;
I: Byte;
ColorTable: array[0..255] of TRGBColor;
pRGB: PRGBColor;
begin
for I := 0 to 126 do
begin
Y := (Abs(128 - I) * Amount) div 256;
ColorTable.r := GetRValue(Byte(I - Y));
ColorTable.g := GetGValue(Byte(I - Y));
ColorTable.b := GetBValue(Byte(I - Y));
end;
for I := 127 to 255 do
begin
Y := (Abs(128 - I) * Amount) div 256;
ColorTable.r := GetRValue(Byte(I + Y));
ColorTable.g := GetGValue(Byte(I + Y));
ColorTable.b := GetBValue(Byte(I + Y));
end;
for Y := 0 to Bmp.Height - 1 do
begin
pRGB := Bmp.ScanLine[Y];
for X := 0 to Bmp.Width - 1 do
begin
pRGB.R := ColorTable[pRGB.R].R;
pRGB.G := ColorTable[pRGB.G].G;
pRGB.B := ColorTable[pRGB.B].B;
Inc(pRGB);
end;
end;
end;

// 改变饱和度
procedure Saturation(var Bmp: TBitmap; Amount: Integer); // Amount: 0~510
var
Grays: array[0..767] of Integer;
Alpha: array[0..255] of Word;
Gray, X, Y: Integer;
pRGB: PRGBColor;
I: Byte;
begin
for I := 0 to 255 do Alpha := (I * Amount) shr 8;
x := 0;
for I := 0 to 255 do
begin
Gray := I - Alpha;
Grays[X] := Gray; Inc(X);
Grays[X] := Gray; Inc(X);
Grays[X] := Gray; Inc(X);
end;
for Y := 0 to Bmp.Height - 1 do
begin
pRGB := Bmp.ScanLine[Y];
for X := 0 to Bmp.Width - 1 do
begin
Gray := Grays[pRGB.R + pRGB.G + pRGB.B];
pRGB.R := Byte(Gray + Alpha[pRGB.R]);
pRGB.G := Byte(Gray + Alpha[pRGB.G]);
pRGB.B := Byte(Gray + Alpha[pRGB.B]);
Inc(pRGB);
end;
end;
end;
 
薄荷兄:
cmyk 模式在 Windows 单元内全部有分解函数,直接把 32bit 的 COLORREF shl 几下就出
来了,应该比 rgb 在 Windows 中的分解还要多。另外,你既然 rgb 已经搞得定了,同样
是 COLORREF 的分解,直接可以搞定这个问题的呀,诸如使用 SetPixel 函数。
 
楼主,我来Show一下我统计的转换函数吧!!!!!!!呵呵~~~~~~~~~~~~

procedure RGBTOCMYK(R , G , B : byte; var C, M, Y, K : byte);
begin
C := 255 - R;
M := 255 - G;
Y := 255 - B;
if C < M then
K := C else
K := M;
if Y < K then
K := Y;
if k > 0 then begin
c := c - k;
m := m - k;
y := y - k;
end;
end;

procedure CMYKTORGB(C , M , Y , K : byte; var R, G, B: byte);
begin
if (Integer(C) + Integer(K)) < 255 then
R := 255 - (C + K) else
R := 0;
if (Integer(M) + Integer(K)) < 255 then
G := 255 - (M + K) else
G := 0;
if (Integer(Y) + Integer(K)) < 255 then
B := 255 - (Y + K) else
B := 0;
end;

procedure ColorCorrectCMYK(var C, M, Y, K: byte);
var
MinColor : byte;
begin
if C < M then
MinColor := C else
MinColor := M;
if Y < MinColor then
MinColor := Y;
if MinColor + K > 255 then
MinColor := 255 - K;
C := C - MinColor;
M := M - MinColor;
Y := Y - MinColor;
K := K + MinColor;
end;
 
to NetSoft:谢谢你的帮助,不过你给的函数我都知道了。而且我的关键不在这。
to 小雨哥:你倒是提醒了我,可以用setpiexls试试,不过速度估计不行,我本来是
打算用scanline,不过那个函数扫描得到的数组是rgb序列,我就不会搞了。
to app2001:谢谢你的资料,不过这些我都有。
 
这个鸟函数快得要命。要注意的倒是你的操作要用MEMDC进行,不要使用加加减减,尤其是
颜色处理的时候,象你已经确定处理 $00E0A0E0 这个红里带青的颜色,直接使用位处理即
可。Scanline 函数是个很慢的操作,不会带来任何好处。
http://www.delphibbs.com/keylife/images/g19/IconCol.rar 是一个图标程序
 
差不多搞定了,用的scanline,不过受了小雨哥的启发。 :)
 
后退
顶部