Ver Mensaje Individual
  #1  
Antiguo 23-06-2008
Avatar de RONPABLO
[RONPABLO] RONPABLO is offline
Miembro Premium
 
Registrado: oct 2004
Posts: 1.514
Reputación: 23
RONPABLO Va por buen camino
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);
__________________
"Como pasa el tiempo..... ayer se escribe sin H y hoy con H"
Responder Con Cita