关于delphi处理图象的难题 请问在delphi中,应该如何处理一幅图象的亮度和对比度等方面的问题!谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //COPY 自XWolf的解答 // Bitmap.ScanLine[X] 可以获取图像象素的内存地址,24Bits的Bitmap的每一象// 素是以三原色RGB的次序存放的,改变RGB的值就可调节Bitmap的色彩.// R, G, B: -255~255procedure 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[I].R := Byte(I + R); ColorTable[I].G := Byte(I + G); ColorTable[I].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; Inc(pRGB); end; end;end;// 改变图像的亮度,也只需调用RGB(Bmp, X, X, X)改变三原色.// 调节Bitmap的对比度// 应用公式: 新颜色值 = (旧颜色值 - 128) * 系数 + 128procedure Contrast(var Bmp: TBitmap; Amount: Integer);// Amount: -255~255var 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[I].r := GetRValue(Byte(I - Y)); ColorTable[I].g := GetGValue(Byte(I - Y)); ColorTable[I].b := GetBValue(Byte(I - Y)); end; for I := 127 to 255 do begin Y := (Abs(128 - I) * Amount) div 256; ColorTable[I].r := GetRValue(Byte(I + Y)); ColorTable[I].g := GetGValue(Byte(I + Y)); ColorTable[I].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~510var 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] := (I * Amount) shr 8; x := 0; for I := 0 to 255 do begin Gray := I - Alpha[I]; 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;//对于Jpg的处理,与Bitmap类似,因为TJpegImage内部有TBitmap.//Bmp := TBitmap.Create;//Bmp.Assign(Jpg);procedure TForm1.FormCreate(Sender: TObject);begin bmp := TBitmap.Create; bmp.Assign(image1.Picture.Graphic);end;procedure TForm1.Button1Click(Sender: TObject);begin RGB(Bmp, StrToInt(edit1.text),StrToInt(edit2.text),StrToInt(edit3.text)); image1.Picture.Graphic.Assign(bmp); image1.Refresh;end;procedure TForm1.Button2Click(Sender: TObject);begin Contrast(Bmp, strtoint(edit1.text)); image1.Picture.Graphic.Assign(bmp); image1.Refresh;end;procedure TForm1.Button3Click(Sender: TObject);begin Saturation(Bmp, strtoint(edit1.text)); image1.Picture.Graphic.Assign(bmp); image1.Refresh;end; 亮度是调节RGB三色的值,同比例的增加或者减少。对比度是设定一个阀值,大于这个阀值的按比例增加三色的值,小于这个阀值就按比例减少三色的值。至于羽化、柔化、反色等等类似。 如何将如下函数转为delphi 函数??在线等》》》 所谓的高素质人才也就是这样的素质! 编译时,怎样不创建可执行文件? 知道了工作组、计算机名,怎么找到IP啊? InstallShield Express问题!在线等待! 毕业设计最后难题:选择dbgrid的某些字段打印的问题,详情见内 谁有数据库导入导出的例子? 谢谢yangkunjie(七郎),先给分 delphi 如何调用c程序??? 如何使用TPrinter达到这样的效果??? 谁有读取CPU序列号或其他硬件唯一标识码的源码,100大洋相送! treeview中如何取同一level的下一个节点?(有子节点的情况)
// 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[I].R := Byte(I + R);
ColorTable[I].G := Byte(I + G);
ColorTable[I].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;
Inc(pRGB);
end;
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[I].r := GetRValue(Byte(I - Y));
ColorTable[I].g := GetGValue(Byte(I - Y));
ColorTable[I].b := GetBValue(Byte(I - Y));
end;
for I := 127 to 255 do
begin
Y := (Abs(128 - I) * Amount) div 256;
ColorTable[I].r := GetRValue(Byte(I + Y));
ColorTable[I].g := GetGValue(Byte(I + Y));
ColorTable[I].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] := (I * Amount) shr 8;
x := 0;
for I := 0 to 255 do
begin
Gray := I - Alpha[I];
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;//对于Jpg的处理,与Bitmap类似,因为TJpegImage内部有TBitmap.//Bmp := TBitmap.Create;
//Bmp.Assign(Jpg);procedure TForm1.FormCreate(Sender: TObject);
begin
bmp := TBitmap.Create;
bmp.Assign(image1.Picture.Graphic);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
RGB(Bmp, StrToInt(edit1.text),StrToInt(edit2.text),StrToInt(edit3.text));
image1.Picture.Graphic.Assign(bmp);
image1.Refresh;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Contrast(Bmp, strtoint(edit1.text));
image1.Picture.Graphic.Assign(bmp);
image1.Refresh;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
Saturation(Bmp, strtoint(edit1.text));
image1.Picture.Graphic.Assign(bmp);
image1.Refresh;
end;
对比度是设定一个阀值,大于这个阀值的按比例增加三色的值,小于这个阀值就按比例减少三色的值。至于羽化、柔化、反色等等类似。