CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    Re: GDI+ screenshot save to JPG

    Use wchar_t instead bcos your application is not a unicode application.

    Code:
    SYSTEMTIME SysTime;
    GetLocalTime(&SysTime);
    wchar_t filename[200];
    memset(filename,0,sizeof(filename));
    wsprintfW(filename,L"screen%02d:%02d:%02d h.jpeg",SysTime.wHour,SysTime.wMinute,SysTime.wSecond);

  2. #17
    Join Date
    May 2009
    Posts
    140

    Re: GDI+ screenshot save to JPG

    thx it compiles... but doesn't save screenshot to anywhere =\ without formatting it was saving it fine , maybe i used filename wrong? =\
    full code
    Code:
    void gdiscreen()
    {
    	SYSTEMTIME SysTime;
    	GetLocalTime(&SysTime);
    	wchar_t filename[200];
    	memset(filename,0,sizeof(filename));
    	wsprintfW(filename,L"C:\\screen%02d:%02d:%02d h.jpeg",SysTime.wHour,SysTime.wMinute,SysTime.wSecond);
    	
    	using namespace Gdiplus;
    	GdiplusStartupInput gdiplusStartupInput;
    	ULONG_PTR gdiplusToken;
    	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    
    	{
    		HDC scrdc, memdc;
    		HBITMAP membit;
    		scrdc = ::GetDC(0);
    		int Height = GetSystemMetrics(SM_CYSCREEN);
    		int Width = GetSystemMetrics(SM_CXSCREEN);
    		memdc = CreateCompatibleDC(scrdc);
    		membit = CreateCompatibleBitmap(scrdc, Width, Height);
    		HBITMAP hOldBitmap =(HBITMAP) SelectObject(memdc, membit);
    		BitBlt(memdc, 0, 0, Width, Height, scrdc, 0, 0, SRCCOPY);
    
    		Gdiplus::Bitmap bitmap(membit, NULL);
    		CLSID clsid;
    		GetEncoderClsid(L"image/jpeg", &clsid);
    		bitmap.Save(filename, &clsid);
    
    		SelectObject(memdc, hOldBitmap);
    
    		DeleteObject(memdc);
    
    		DeleteObject(membit);
    
    		::ReleaseDC(0,scrdc);
    	}
    
    	GdiplusShutdown(gdiplusToken);
    }

  3. #18
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    Re: GDI+ screenshot save to JPG

    You need to put the drive and folder path for the file path. If you are using Vista and is using UAC, your application do not have the permission to save to C drive. Use C drive and a folder in your file path.
    Last edited by CBasicNet; May 14th, 2009 at 05:00 AM. Reason: Edited for Vista

  4. #19
    Join Date
    May 2009
    Posts
    140

    Re: GDI+ screenshot save to JPG

    but it was saving to C drive fine when i used only screen.jpg as a name, you sure about permissions?

  5. #20
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    Re: GDI+ screenshot save to JPG

    Perhaps colon ":" is not valid for a file name.

  6. #21
    Join Date
    May 2009
    Posts
    140

    Re: GDI+ screenshot save to JPG

    oops my bad, thx

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured