|
제가 맹글어서 사용하고 있는 함수입니다.
화면을 캡쳐하는 것입니다.
주석이 달려 있으니 그리 어렵지 않을 겁니다.
//---------------------------------------------------------------------------
// 화면(CRT)을 그림파일으로 저장하는 함수
// 저장타입 : bmp, jpg
// width : 저장할 너비, height : 저장할 높이
bool __fastcall CRT2File (const String &f_name, TRect &area, int width, int height)
{
int f_type = -1;
if ( width <= 0 || height <= 0 ) return false;
if ( f_name == "" ) return false;
else if ( f_name.SubString (f_name.Length () - 3, 4).UpperCase () == ".BMP" ) f_type = 0;
else if ( f_name.SubString (f_name.Length () - 3, 4).UpperCase () == ".JPG" ) f_type = 1;
if ( f_type < 0 ) return false;
if ( FileExists (f_name) )
DeleteFile (f_name);
Graphics::TBitmap *bmp = new Graphics::TBitmap ();
try
{
GetCRT (bmp, area, width, height);
switch ( f_type )
{
case 0:
bmp->SaveToFile (f_name);
break;
case 1:
TJPEGImage *j_file = new TJPEGImage ();
try
{
j_file->Assign (bmp);
j_file->SaveToFile (f_name);
}
__finally
{ delete j_file; }
break;
}
}
__finally
{
bmp->FreeImage ();
delete bmp;
bmp = NULL;
}
return true;
}
//---------------------------------------------------------------------------
// 화면(CRT)을 그림 Stream으로 저장하는 함수
// 저장타입 : bmp, jpg
// width : 저장할 너비, height : 저장할 높이
bool __fastcall CRT2Stream (TStream *st, TRect &area, int width, int height, int type)
{
if ( width <= 0 || height <= 0 ) return false;
if ( type != kBMP && type != kJPG ) return false;
Graphics::TBitmap *bmp = new Graphics::TBitmap ();
try
{
GetCRT (bmp, area, width, height);
switch ( type )
{
case 0:
bmp->SaveToStream (st);
break;
case 1:
TJPEGImage *jpg = new TJPEGImage ();
try
{
jpg->Assign (bmp);
jpg->SaveToStream (st);
}
__finally
{ delete jpg; }
break;
}
}
__finally
{
bmp->FreeImage ();
delete bmp;
bmp = NULL;
}
return true;
}
//---------------------------------------------------------------------------
// 화면(CRT)을 그림으로 읽어오는 함수
// bmp : 화면을 받을 클래스
// width : 받아올 화면의 너비
// height : 〃 높이
void __fastcall GetCRT (Graphics::TBitmap *bmp, TRect& area, int width, int height)
{
bmp->Width = width;
bmp->Height = height;
int col_num = GetCRTColorBit ();
if ( col_num == 4 ) bmp->PixelFormat = pf4bit;
else if ( col_num >= 16 ) bmp->PixelFormat = pf16bit;
else bmp->PixelFormat = pf8bit;
HWND desktop = GetDesktopWindow ();
HDC dt_dc = GetDC (desktop);
SetStretchBltMode (bmp->Canvas->Handle, STRETCH_HALFTONE);
StretchBlt (bmp->Canvas->Handle, 0,0, width, height,
dt_dc, area.Left, area.Top, area.Right - area.Left, area.Bottom - area.Top, SRCCOPY);
// dt_dc, 0,0, Screen->Width, Screen->Height, SRCCOPY);
ReleaseDC (desktop, dt_dc);
}
//---------------------------------------------------------------------------
int __fastcall GetCRTColorBit (void)
{
int color_bit;
HDC dc;
dc = GetDC (0);
try
{ color_bit = GetDeviceCaps (dc, PLANES) * GetDeviceCaps (dc, BITSPIXEL); }
__finally
{ ReleaseDC (0, dc); }
return color_bit;
}
//---------------------------------------------------------------------------
인영 님이 쓰신 글 :
: 윈도우 에 떠있는 응용프로그램을 캡쳐하고 싶은데 어떻게 해야할지~
: 제가 아직 너무 초보인데 꼭하고 싶은것이 있어서여....정말 재미있을것같기두 하고 해서
: 그러거든여 제가 지금 생각하고 있는것은 타임으로 무한 로프를 돌려서 응용 프로그램을 캡쳐해서저장을 시키구 1초에 한번씩 한번씩 지워지면서 다른이미지가 저장 되는것이지요^^
: 근데 생각처럼 쉽지가 않은것같아서여....정말 하구 싶은데 고수님들 도움좀 주시면
: 안될까여?c++빌더를 정말 좋아하는데 어떻게 고급을 배울 방법이 없네여
: 네가 영어를 그렇게 잘하는 편도 아니여서 외국 서적은 볼수가 없구
: 의지할대라구는 여기 밖에 없어서여...
: 꼭좀 부탁드립니다.
|