Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 팁&트릭
Delphi Programming Tip&Tricks
[186] 화면 스크린샷
civilian,안영제 [civilian] 6004 읽음    2005-12-01 19:17
화면의 특정 영역을 Jpeg로 저장하는 코드입니다.
현재 작업중인 프로그램의 일부인데, 유용하게 사용하시길 바랍니다.

procedure ScreenShot(
       const ARect: TRect;              // 저장할 화면 영역
       AFileName: String;                 // 저장할 파일명
       ALayer: Boolean = False;      // 레이어 윈도 캡쳐 ( Win2000 이상)
       ACursor: Boolean = False;    // 영역내에 커서가 있는 경우 커서 그리기
       AQuality: Integer = 75);          // 압축 품질
var
  Bitmap: TBitmap;
  Jpeg: TJpegImage;
  DC: HDC;
  ACursorInfo: Windows.TCursorInfo;
  AIconInfo: ICONINFO;
begin
  Bitmap := TBitmap.Create;
  Jpeg := TJpegImage.Create;

  try
    with Bitmap do
    begin
      PixelFormat := pf24Bit;
      Width := ARect.Right - ARect.Left + 1;
      Height := ARect.Bottom - ARect.Top + 1;
    end;

    DC := GetDC(0);

    try
      if ALayer then
        BitBlt(Bitmap.Canvas.Handle, 
                 0, 0, Bitmap.Width, Bitmap.Height, DC, ARect.Left, ARect.Top, SRCCOPY or $40000000)
      else
        BitBlt(Bitmap.Canvas.Handle, 
                 0, 0, Bitmap.Width, Bitmap.Height, DC, ARect.Left, ARect.Top, SRCCOPY);

      if ACursor then
      begin
        ACursorInfo.cbSize := SizeOf(ACursorInfo);
        GetCursorInfo(ACursorInfo);

        Dec(ACursorInfo.ptScreenPos.X, ARect.Left);
        Dec(ACursorInfo.ptScreenPos.Y, ARect.Top);

        //
        // 핫스팟 위치 보정
        //
        if GetIconInfo(ACursorInfo.hCursor, AIconInfo) then
        begin
          Dec(ACursorInfo.ptScreenPos.x, AIconInfo.xHotspot);
          Dec(ACursorInfo.ptScreenPos.y, AIconInfo.yHotspot);

          if (AIconInfo.hbmMask <> 0) then DeleteObject(AIconInfo.hbmMask);
          if (AIconInfo.hbmColor <> 0) then DeleteObject(AIconInfo.hbmColor);
        end;
      
        //
        // 커서 그리기
        //
        DrawIcon(Bitmap.Canvas.Handle, 
                       ACursorInfo.ptScreenPos.x, ACursorInfo.ptScreenPos.y, ACursorInfo.hCursor);
      end;
    finally
      ReleaseDC(0, DC);
    end;

    with Jpeg do
    begin
      Assign(Bitmap);
      CompressionQuality := AQuality;  // Jpeg 파일 퀄러티 (~100)
      Compress;
      SaveToFile(AFileName);
    end;
  finally
    Bitmap.Free;
    Jpeg.Free;
  end;
end;

+ -

관련 글 리스트
186 화면 스크린샷 civilian,안영제 6004 2005/12/01
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.