Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Gráficos (https://www.clubdelphi.com/foros/forumdisplay.php?f=8)
-   -   copiar un sector de imagen que no esta visible (https://www.clubdelphi.com/foros/showthread.php?t=57645)

RONPABLO 23-06-2008 21:02:42

copiar un sector de imagen que no esta visible
 
hola, tengo el siguiente procedimiento con el cual recorro una imagen origen y capturo el sector entre un área determinada en el que se encuentre el color negro, el área determinada es variable en su altura, de forma tal que siempre se recorre en X desde el punto 0 hasta el tamañano de la imagen y en Y desde y hasta un punto varibale dentro del rango de Y, el problema es que para poder copiar el sector tiene que estar visible dicha imagen origen y necesito que no este visible, la imagen la cargo desde un stream a un TImage....


Código Delphi [-]
procedure TFSectorVisualizar.asignarImagen(inY, finY : Integer);
var
  x,y, x1, y1, xIni, yIni : Integer;
  BitMap : TBitMap;
  P : PByteArray;
  lColor : TColor;
  rectanOrigen : TRect;
begin
  try
    x1 := 0;
    y1 := 0;
    xIni := ImagenOrigen.Width;
    yIni := ImagenOrigen.Height;
    Bitmap := TBitmap.Create;
    Bitmap.Width:= ImagenOrigen.Width;
    Bitmap.Height:= ImagenOrigen.Height;
    Bitmap.Canvas.Draw(0,0,ImagenOrigen.Picture.Graphic);
    for y := inY to FinY do
    begin
      for x := 0 to BitMap.Width -1 do
      begin
         if BitMap.Canvas.Pixels[x,y] = clblack then
         begin
            if x > x1 then
               x1 := x;
            if y > y1 then
               y1 := y;
            if x < xIni then
               xIni := x;
            if y < yIni then
               yIni := y;
         end;
      end;
    end;
    imDestino.Width :=  x1 - xIni;
    imDestino.Height :=  y1 - yIni;
    xIni := ImagenOrigen.Left  + xIni;
    yIni := ImagenOrigen.Top + yIni;
    rectanOrigen := rect(xIni, yIni, x1, y1);
    if (x1 > xIni) and (y1 > YIni) then
          Copiar(Canvas.Handle,imPaciente.Canvas.Handle,rectanOrigen,1)
  finally
  end;
end;


procedure TFSectorVisualizar.Copiar(SrcDC, DestDc: HDC; SrcRect: TRect; Zoom: Integer);
begin
  StretchBlt(DestDC, 0,0, SrcRect.Right, SrcRect.Bottom, SrcDC, SrcRect.Left,
    SrcRect.Top, SrcRect.Right, SrcRect.Bottom, SRCCOPY);
end;


Y para llamar la función lo hago así:

Código Delphi [-]
    asignarImagen(0, 224);
    // ó asignarImagen(20, 100);

RONPABLO 23-06-2008 23:33:46

Solución... (perdí tanto tiempo tratando de hacer esto y ahora que lo hice lo veo tan fácil, hay días que no le acierto un tiro al mundo aunque este hinchado.... :eek::eek::eek::eek:)
Código Delphi [-]
procedure TFSectorVisualizar.asignarImagen(inY, finY : Integer);
var
  x,y, x1, y1, xIni, yIni : Integer;
  BitMap : TBitMap;
  P : PByteArray;
  lColor : TColor;
  rectanOrigen : TRect;
begin
  try
    x1 := 0;
    y1 := 0;
    xIni := ImagenOrigen.Width;
    yIni := ImagenOrigen.Height;
    Bitmap := TBitmap.Create;
    Bitmap.Width:= ImagenOrigen.Width;
    Bitmap.Height:= ImagenOrigen.Height;
    Bitmap.Canvas.Draw(0,0,ImagenOrigen.Picture.Graphic);
    for y := inY to FinY do
    begin
      for x := 0 to BitMap.Width -1 do
      begin
         if BitMap.Canvas.Pixels[x,y] = clblack then
         begin
            if x > x1 then
               x1 := x;
            if y > y1 then
               y1 := y;
            if x < xIni then
               xIni := x;
            if y < yIni then
               yIni := y;
         end;
      end;
    end;
    if (x1 > xIni) and (y1 > YIni) then
    begin
       imDestino.Width :=  x1 - xIni;
       imDestino.Height :=  y1 - yIni;
        rectanOrigen := rect(xIni, yIni, x1, y1);
        imDestino.Canvas.CopyRect(Rect(0,0, x1 - xIni, y1 - yIni),BitMap.Canvas,rectanOrigen);
    end;
  finally
  end;
end;


La franja horaria es GMT +2. Ahora son las 15:22:50.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi