화면의 특정 영역을 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;
|