Programming/Delphi

프로그램 화면을 이미지로 저장하기

통통만두 2010. 6. 30. 15:37
반응형
function Tfrm_100.GetPanelImage(Panel:TPanel): TBitmap;
var
  Ofs: Integer;
begin
  if Assigned(Panel) then
  begin
      Result := TBitmap.Create;
      try
        Result.Width := Panel.ClientWidth;
        Result.Height := Panel.ClientHeight;
        Result.Canvas.Brush := Panel.Brush;
        Result.Canvas.FillRect(Panel.ClientRect);
        Result.Canvas.Lock;
        try
          if GetWindowLong(Panel.Handle, GWL_STYLE) and WS_BORDER <> 0 then
            Ofs := -1  // Don't draw form border
          else
            Ofs := 0;  // There is no border
          Panel.PaintTo(Result.Canvas.Handle, Ofs, Ofs);
        finally
          Result.Canvas.Unlock;
        end;
      except
        Result.Free;
        raise;
      end;
  end;
end; 
반응형