标签:
呃,一直想有一个这样功能的软件,但是貌似木有找到啊。
于是自己写了一个比较挫的。。
思路,截取ForegroundWindow图像生成png
void SavePictureAsPng(LPCTSTR lpFile) { HWND hwnd = GetForegroundWindow(); HDC hdcSrc = GetDC(hwnd); int nBitPerPixel = GetDeviceCaps(hdcSrc, BITSPIXEL); int nWidth = GetDeviceCaps(hdcSrc, HORZRES); int nHeight = GetDeviceCaps(hdcSrc, VERTRES); CImage image; image.Create(nWidth, nHeight, nBitPerPixel); BitBlt(image.GetDC(), 0, 0, nWidth, nHeight, hdcSrc, 0, 0, SRCCOPY); ReleaseDC(NULL, hdcSrc); image.ReleaseDC(); image.Save(lpFile, Gdiplus::ImageFormatPNG); }
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: Place code here. MSG msg = {0}; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_SCREENCAPTURE, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SCREENCAPTURE)); for (int i = 0; i < 10; i++) { TCHAR strFile[MAX_PATH]; StringCchPrintf(strFile, RTL_NUMBER_OF(strFile), _T("D:\\Leen\\%02d.png"),i); SavePictureAsPng(strFile); Sleep(300); } LaunchWithShellExecuteEx(_T("D:\\Leen\\TestGif.exe"), NULL, SW_SHOW,TRUE); LaunchWithShellExecuteEx(_T("D:\\Leen\\Test.Gif"), NULL, SW_SHOW, FALSE); // Main message loop: /*while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } }*/ return (int) msg.wParam; }
int main(array<System::String ^> ^args) { // Console::WriteLine(L"Hello World"); String^ outputFilePath = L"D:\\Leen\\test.gif"; AnimatedGifEncoder^ e = gcnew AnimatedGifEncoder; e->Start(outputFilePath); e->SetDelay(200); //-1:no repeat,0:always repeat e->SetRepeat(0); int i = 0; for ( i = 0; i < 10; i++) { String^ imageFilePath = String::Format(L"D:\\Leen\\{0:00}.png", i); e->AddFrame(Image::FromFile(imageFilePath)); } e->Finish(); /* extract Gif */ String^ outputPath = L"D:\\Leen\\"; GifDecoder^ gifDecoder = gcnew GifDecoder(); gifDecoder->Read(outputFilePath); for (int i = 0, count = gifDecoder->GetFrameCount(); i < count; i++) { Image^ frame = gifDecoder->GetFrame(i); // frame i frame->Save(outputPath + Guid::NewGuid().ToString() + L".png", ImageFormat::Png); } return 0; }
</pre><pre class="cpp" name="code" snippet_file_name="blog_20160510_5_5738037" code_snippet_id="1677473">
参考资料:
标签:
原文地址:http://blog.csdn.net/linlin003/article/details/51362370