Fórum Efeitos em Imagens #413454
28/02/2012
0
Como inverter as cores.
Efeito Preto e branco,inverter e mudar a tonalidade da imagem
Arthur Scarpelli
Curtir tópico
+ 0Posts
29/02/2012
Joel Rodrigues
Primeiramente vou tentar explicar o algorítmo:
um tom de cinza é uma cor onde as três componentes possuem valores iguais (R=G=B). Então varri toda a imagem (pixel a pixel), peguei os valores R, G e B de cada pixel e verifiquei qual o maior deles, passando para uma variável Tom. Encontrando o valor de Tom, definir que aquele pixel teria uma cor onde R=G=B=Tom, ou seja, RGB(Tom, Tom, Tom).
Agora o código:
---------------------------------------------------------
var
i, j:integer; //variáveis para loop
R, G, B:Integer; //valores Red, Green e Blue de cada pixel da imagem
Tom :Integer; //receberá o valor da maior componente (R, G ou B)
begin
for i := 0 to Image1.Width do
begin
for j := 0 to Image1.Width do
begin
R := GetRValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
G := GetGValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
B := GetBValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
if R > G then
begin
if R > B then
Tom := R
else
Tom := B;
end
else
begin
if G > B then
Tom := G
else
Tom := B;
end;
Image1.Picture.Bitmap.Canvas.Pixels[i,j] := RGB(Tom, Tom, Tom);
end;
end;
end;
---------------------------------------------------------
Sim, esse processo pode demorar, mas veja que o Delphi não é um editor de imagem. Esse algorítmo funciona, só acho que não vale a pena implementar em sua aplicação. Mas fia a seu critério.
Boa sorte.
Gostei + 0
29/02/2012
Joel Rodrigues
Primeiramente vou tentar explicar o algorítmo:
um tom de cinza é uma cor onde as três componentes possuem valores iguais (R=G=B). Então varri toda a imagem (pixel a pixel), peguei os valores R, G e B de cada pixel e verifiquei qual o maior deles, passando para uma variável Tom. Encontrando o valor de Tom, definir que aquele pixel teria uma cor onde R=G=B=Tom, ou seja, RGB(Tom, Tom, Tom).
Agora o código:
---------------------------------------------------------
var
i, j:integer; //variáveis para loop
R, G, B:Integer; //valores Red, Green e Blue de cada pixel da imagem
Tom :Integer; //receberá o valor da maior componente (R, G ou B)
begin
for i := 0 to Image1.Width do
begin
for j := 0 to Image1.Width do
begin
R := GetRValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
G := GetGValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
B := GetBValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
if R > G then
begin
if R > B then
Tom := R
else
Tom := B;
end
else
begin
if G > B then
Tom := G
else
Tom := B;
end;
Image1.Picture.Bitmap.Canvas.Pixels[i,j] := RGB(Tom, Tom, Tom);
end;
end;
end;
---------------------------------------------------------
Sim, esse processo pode demorar, mas veja que o Delphi não é um editor de imagem. Esse algorítmo funciona, só acho que não vale a pena implementar em sua aplicação. Mas fia a seu critério.
Boa sorte.
Gostei + 0
29/02/2012
Joel Rodrigues
var
i, j:integer;
R, G, B:Integer;
Lum:Integer;
begin
Self.DoubleBuffered := True;
for i := 0 to Image1.Width do
begin
for j := 0 to Image1.Height do
begin
R := GetRValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
G := GetGValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
B := GetBValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
Lum := Round(R*0.3 + G*0.59 + B*0.11);
Image1.Picture.Bitmap.Canvas.Pixels[i,j] := RGB(Lum, Lum, Lum);
end;
end;
Gostei + 0
29/02/2012
Joel Rodrigues
var
i, j:integer;
R, G, B:Integer;
Tom :Integer;
maior, med:Integer;
begin
Self.DoubleBuffered := True;
maior := 0;
for i := 0 to Image1.Width do
begin
for j := 0 to Image1.Height do
begin
R := GetRValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
G := GetGValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
B := GetBValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
if R > G then
begin
if R > B then
Tom := R
else
Tom := B;
end
else
begin
if G > B then
Tom := G
else
Tom := B;
end;
if Tom > maior then
maior := Tom;
end;
end;
med := Round(maior/2);
for i := 0 to Image1.Width do
begin
for j := 0 to Image1.Height do
begin
R := GetRValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
G := GetGValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
B := GetBValue(ColorToRGB(Image1.Picture.Bitmap.Canvas.Pixels[i,j]));
if R > G then
begin
if R > B then
Tom := R
else
Tom := B;
end
else
begin
if G > B then
Tom := G
else
Tom := B;
end;
if Tom < med then
Image1.Picture.Bitmap.Canvas.Pixels[i,j] := RGB(255, 255, 255)
else
Image1.Picture.Bitmap.Canvas.Pixels[i,j] := RGB(0, 0, 0);
end;
end
end;
Gostei + 0
29/02/2012
Arthur Scarpelli
Gostei + 0
29/02/2012
Joel Rodrigues
Gostei + 0
29/02/2012
Deivison Melo
Pode baixe ele através do site:
http://www.torry.net/quicksearchd.php?String=ImageEn+&Title=Yes
Gostei + 0
29/02/2012
Joel Rodrigues
Gostei + 0
02/03/2012
Arthur Scarpelli
Gostei + 0
14/03/2012
Joao Silva
mas so funciona com bitmaps.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)