Ver Mensaje Individual
  #4  
Antiguo 19-02-2007
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 26
seoane Va por buen camino
Y ya que estamos podemos obtener bonitos resultados con este metodo. Podemos realzar los bordes de una imagen, como si estuviera perfilada con un rotulador negro, como en un comic.

Código Delphi [-]
type
  TRGB = array[1..3] of Byte;
  PRGB = ^TRGB;
  TFila = array[1..3] of TRGB;
  PFila = ^TFila;

function Calcular(F1, F2, F3: PFila; i,j, Umbral: integer): TRGB;
var
  k: integer;
begin
  for k:= 1 to 3 do
  begin
    Result[k]:=
      Trunc(
        sqrt(
          // Horizontal
          sqr((F1[1][k]*(-1)) + (F1[i][k]*(-2)) + (F1[j][k]*(-1)) +
              (F3[1][k]*1) + (F3[i][k]*2) +(F3[j][k]*1)) +
          // Vertical
          sqr((F1[1][k]*(-1)) + (F1[j][k]*1) +
              (F2[1][k]*(-2)) + (F2[j][k]*2) +
              (F3[1][k]*(-1)) + (F3[j][k]*1) )
        ) / 5.66
      );
    //  --- Esta es la parte importante --- 
    // Pintamos los bordes de negro y dejamos sin tocar el resto de la imagen
    if Umbral > 0 then
      if Result[k] > Umbral then
      begin
        FillChar(Result,Sizeof(Result),0);
        break;
      end else
        Result[k]:= F2[i][k];
  end;
end;

procedure Comic(Img: TPicture; Umbral: Integer);
var
  Bitmap: TBitmap;
  P1,P2,P3,P4: PByte;
  i,j: Integer;
begin
  Bitmap:= TBitmap.Create;
  try
    Bitmap.Width:= Img.Width;
    Bitmap.Height:= Img.Height;
    Bitmap.Canvas.Draw(0,0,Img.Graphic);
    if not (Img.Graphic is TBitmap) then
      Img.Assign(Bitmap);
    Img.Bitmap.PixelFormat:= pf24bit;
    Bitmap.PixelFormat:= pf24bit;
    for j:= -1 to Bitmap.Height - 2 do
    begin
      // Ajustamos el borde superior
      if j < 0 then
        P1:= Bitmap.ScanLine[0]
      else
        P1:= Bitmap.ScanLine[j];
      P2:= Bitmap.ScanLine[j+1];
      // Ajustamos el borde inferior
      if j > Bitmap.Height - 3 then
        P3:= Bitmap.ScanLine[Bitmap.Height - 1]
      else
        P3:= Bitmap.ScanLine[j+2];
      P4:= Img.Bitmap.ScanLine[j+1];
      // Primera columna
      PFila(P4)[1]:=
        Calcular(PFila(P1),PFila(P2),PFila(P3),1,2,Umbral);
      for i:= 0 to Bitmap.Width - 3 do
      begin
        PFila(P4)[2]:=
          Calcular(PFila(P1),PFila(P2),PFila(P3),2,3,Umbral);
        inc(P1,Sizeof(TRGB));
        inc(P2,Sizeof(TRGB));
        inc(P3,Sizeof(TRGB));
        inc(P4,Sizeof(TRGB));
      end;
      // Ultima columna
      PFila(P4)[2]:=
        Calcular(PFila(P1),PFila(P2),PFila(P3),2,2,Umbral);
    end;
  finally
    Bitmap.Free;
  end;
end;

// Por ejemplo
  Comic(Image1.Picture,16);
  Image1.Refresh;
Dependiendo de la imagen original y el valor de umbral que escojamos, podemos conseguir un efecto bastante bueno.

PD: Delphius este ultimo mensaje, es solo lúdico. Espero que no te importe
Responder Con Cita