Oppure

Loading
05/03/10 19:44
systemgvp
salve,
devo convertire un'immagine contenuta in una Timage in una contenuta in un'altra Timage, ma al momento l'unica procedura che mi è venuta in mente è:

function bmptosepia(const bmp: TBitmap; depth: Integer): Boolean;
var color,color2:longint; r,g,b,rr,gg:byte; h,w:integer;
begin
for h := 0 to bmp.height do
begin
for w := 0 to bmp.width do
begin
color:=colortorgb(bmp.Canvas.pixels[w,h]);
r:=getrvalue(color);
g:=getgvalue(color);
b:=getbvalue(color);
color2:=(r+g+b) div 3;
bmp.canvas.Pixels[w,h]:=RGB(color2,color2,color2);
color:=colortorgb(bmp.Canvas.pixels[w,h]);
r:=getrvalue(color);
g:=getgvalue(color);
b:=getbvalue(color);
rr:=r+(depth*2);
gg:=g+depth;
if rr <= ((depth*2)-1) then
rr:=255;
if gg <= (depth-1) then
gg:=255;
bmp.canvas.Pixels[w,h]:=RGB(rr,gg,b);
end;
end;
end;

bmptosepia(image1.picture.bitmap, 20);

il problema è che è troppo lenta perchè si gira tutti i pixel, avevo letto qualcosa sulla procedura Bitmap.Scanline, ma non ho trovato monlto, solo quest'esempio per avere l'immagine inversa che oltrettutto non è che abbia capito più di tanto, anche se però è nettamente più veloce e soddisfacente.

procedure invertire32Bit(Bitmap: TBitmap);
var
i, j: Integer;
P: PDWord;
begin
p := Bitmap.Scanline[Bitmap.Height - 1];
for j := 1 to Bitmap.Height * Bitmap.Width do
begin
p^ := not p^;
Inc(p);
end;
Bitmap.Assign(bitmap);
end;

invertire32Bit(Image1.Picture.Bitmap);

qualche aiuto per ottenere una procedura (rapida) per convertire in scala di grigi?
e qualche esempio su questo tipo di manipolazioni sulle immagini?
aaa
05/03/10 21:07
systemgvp
credo di aver risolto da solo il problema con

Procedure GrayScale(Bitmap:TBitmap);
var
Row:^TRGBTriple;
H,V,Index:Integer;
begin
Bitmap.PixelFormat:=pf24bit;
for V:=0 to Bitmap.Height-1 do
begin
Row:=Bitmap.ScanLine[V];
for H:=0 to Bitmap.Width -1 do
begin
Index := ((Row.rgbtRed * 77 + Row.rgbtGreen* 150 + Row.rgbtBlue * 29) shr 8);
Row.rgbtBlue:=Index;
Row.rgbtGreen:=Index;
Row.rgbtRed:=Index;
inc(Row);
end;
end;
end;
aaa