Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

c++ & gdi+: stretch a screenshot

Featured Replies

Posted

hi,

for quiet some time i am occupied by this little assignment:

Take a screenshot, shrink it (while preserving the aspect ration) and save it to disk.

my code:


int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
using namespace Gdiplus;
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure pImageCodecInfo = (ImageCodecInfo*)(GlobalAlloc(0,size));
if(pImageCodecInfo == NULL)
return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
GlobalFree(pImageCodecInfo);
return j; // Success
}
} GlobalFree(pImageCodecInfo);
return 0;
}int main()
{
ULONG_PTR m_gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
Bitmap* bm = new Bitmap(1450,1050,PixelFormat32bppARGB);//create an empty image HDC scrn = GetDC(0);//take screenshot
Graphics gr(scrn);//assign it to a graphics object gr.DrawImage(bm,100,100,1450,1050);//shrink it to 100x100 CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);//get jpg encoder bm->Save(L"D:\\wtf.jpg",&clsid);//save image return 0;
}

obviously i am not the greatest gdi+ expert around...

but i cant see why this code just fails without any error (image is just not created....)

Edited by deepzero

Looks like you forgot to fill gdiplusStartupInput, at least .GdiplusVersion must be 1

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.