【发布时间】:2011-01-09 23:23:35
【问题描述】:
在此处下载源代码:http://www.eyeClaxton.com/download/delphi/ColorSwap.zip
是的,我想将“大部分为蓝色”的内容转换为“大部分为绿色”的内容。
我想获取原始位图(浅蓝色)并将颜色(逐个像素)更改为红色、绿色、蓝色和灰色的等价关系。为了理解我的意思,我提供了源代码和屏幕截图。任何帮助将不胜感激。如果需要更多信息,请随时询问。
如果您可以查看下面的代码,我有三个函数正在寻求帮助。 “RGBToRed、RGBToGreen 和 RGBToRed”函数我似乎想不出正确的公式。
unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TMainFrm = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Panel2: TPanel;
Label2: TLabel;
Button1: TButton;
BeforeImage1: TImage;
AfterImage1: TImage;
RadioGroup1: TRadioGroup;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainFrm: TMainFrm;
implementation
{$R *.DFM}
function RGBToGray(RGBColor: TColor): TColor;
var
Gray: Byte;
begin
Gray := Round(
(0.90 * GetRValue(RGBColor)) +
(0.88 * GetGValue(RGBColor)) +
(0.33 * GetBValue(RGBColor)));
Result := RGB(Gray, Gray, Gray);
end;
function RGBToRed(RGBColor: TColor): TColor;
var
Red: Byte;
begin
// Not sure of the algorithm for this color
Result := RGB(Red, Red, Red);
end;
function RGBToGreen(RGBColor: TColor): TColor;
var
Green: Byte;
begin
// Not sure of the algorithm for this color
Result := RGB(Green, Green, Green);
end;
function RGBToBlue(RGBColor: TColor): TColor;
var
Blue: Byte;
begin
// Not sure of the algorithm for this color
Result := RGB(Blue, Blue, Blue);
end;
procedure TMainFrm.FormCreate(Sender: TObject);
begin
BeforeImage1.Picture.LoadFromFile('Images\RightCenter.bmp');
end;
procedure TMainFrm.Button1Click(Sender: TObject);
var
Bitmap: TBitmap;
I, X: Integer;
Color: Integer;
begin
Bitmap := TBitmap.Create;
try
Bitmap.LoadFromFile('Images\RightCenter.bmp');
for X := 0 to Bitmap.Height do
begin
for I := 0 to Bitmap.Width do
begin
Color := ColorToRGB(Bitmap.Canvas.Pixels[I, X]);
case Color of
$00000000: ; // Skip any Color Here!
else
case RadioGroup1.ItemIndex of
0: Bitmap.Canvas.Pixels[I, X] := RGBToBlue(Color);
1: Bitmap.Canvas.Pixels[I, X] := RGBToRed(Color);
2: Bitmap.Canvas.Pixels[I, X] := RGBToGreen(Color);
3: Bitmap.Canvas.Pixels[I, X] := RGBToGray(Color);
end;
end;
end;
end;
AfterImage1.Picture.Graphic := Bitmap;
finally
Bitmap.Free;
end;
end;
end.
好的,我很抱歉没有说得更清楚。我正在尝试获取位图(蓝色)并将蓝色像素与另一种颜色交换。就像下面的照片。
【问题讨论】:
-
我不明白。您提供的代码在哪些方面尚未满足您的需求?
-
好的,我喜欢你提供的截图和代码,但我没有从我们这里得到你想要的。问题是什么,或者哪个部分没有按您想要的方式工作?
-
如果您可以看看上面的代码,我有三个函数正在寻求帮助。 “RGBToRed、RGBToGreen 和 RGBToRed”函数我似乎想不出正确的公式。
-
所以你想让所有的红色也变成绿色(看看窗口的 X)。有上千种方法可以将“大部分是蓝色”的东西变成“大部分是绿色”的东西,我希望你知道。
-
好的,我会重新组合,稍后尝试用另一种方式提问。