NO

Author Topic: Save Screen in JPG file - Grabar Pantalla en Archivo JPG  (Read 4761 times)

lucindom

  • Guest
Save Screen in JPG file - Grabar Pantalla en Archivo JPG
« on: February 14, 2007, 05:18:12 pm »
Example to Save Screen in File

FUNCTIONS:
// Get CLSID
int GetEncoderClsid(const WCHAR * format, CLSID * pClsid)
{
   UINT num = 0;   // number of image encoders
   UINT size = 0;   // size of the image encoder array in bytes

   IMAGECODECINFO *pImageCodecInfo = NULL;

   GdipGetImageEncodersSize(&num, &size);
   if (size == 0)
      return -1;   // Failure

   pImageCodecInfo = malloc(size);
   if (pImageCodecInfo == NULL)
      return -1;   // Failure

   GdipGetImageEncoders(num, size, pImageCodecInfo);

   for (UINT j = 0; j < num; ++j)
   {
      if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0)
      {
         *pClsid = pImageCodecInfo[j].Clsid;
         free(pImageCodecInfo);
         return j;   // Success
      }
   }

   free(pImageCodecInfo);
   return -1;   // Failure
}


PUT THIS CODE IN A BUTTON OR IN SOME PART OF YOUR PROGRAM

   ULONG_PTR gdiplusToken;
   char snom[MAX_PATH ];
   WCHAR sficnom[MAX_PATH ];
   char sdir[MAX_PATH ];

                // INIT GDI
   GdiplusStartup(&gdiplusToken, &g_GdiplusStartupInput, NULL);

   CLSID encoderClsid;
   GetEncoderClsid(L"image/jpeg", &encoderClsid);

   ENCODERPARAMETERS encoderParameters;
   ULONG quality;
   HWND hw;
   HDC hDCSrc, hDCMemory;
   HBITMAP hBmp, hBmpPrev;
   long t;
   SYSTEMTIME st;
   //GpStatus lRes;

    // COPY SCREEN TO BITMAP
    hw = GetDesktopWindow();
    hDCSrc = GetWindowDC(hw);
    hDCMemory = CreateCompatibleDC(hDCSrc);
    hBmp = CreateCompatibleBitmap(hDCSrc, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN));
    hBmpPrev = SelectObject(hDCMemory, hBmp);
    BitBlt(hDCMemory, 0, 0, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN), hDCSrc, 0, 0, SRCCOPY);
    hBmp = SelectObject(hDCMemory, hBmpPrev);
    DeleteDC(hDCMemory);
    ReleaseDC(hw, hDCSrc);

   // COPY BITMAP TO GDI BITMAP
    GdipCreateBitmapFromHBITMAP(hBmp, 0,  (GP_GPBITMAP** ) &t);
    DeleteObject (hBmp);
   
   encoderParameters.Count = 1;
   encoderParameters.Parameter[0].Guid = EncoderQuality;
   encoderParameters.Parameter[0].Type = eEncoderParameterValueTypeLong;
   encoderParameters.Parameter[0].NumberOfValues = 1;

   // Save the image as a JPEG with quality level 100.
   quality = 100;
   encoderParameters.Parameter[0].Value = &quality;

                // GET CURRENT DATE TIME
   GetSystemTime( &st );
               // GET ACTIVE DIRECTORY
   GetCurrentDirectory( MAX_PATH, (LPTSTR) sdir);
               // CREATE FILE NAME WITH CURRENT DATE TIME
   wsprintf( snom, "%s\\P%4.4d%02.2d%02.2d%02.2d%02.2d%3.3d.jpg", sdir,st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond );   
               // CONVERT TO WIDE THE NAME
   MultiByteToWideChar(CP_OEMCP,MB_COMPOSITE, snom, lstrlen(snom), sficnom,  MAX_PATH);
                // SAVE IMAGE TO FILE
   GdipSaveImageToFile( (GP_GPIMAGE *) t,  sficnom, &encoderClsid, &encoderParameters);

                // CLOSE GDI.
   GdipDisposeImage ( (GP_GPIMAGE *) t );
   GdiplusShutdown(gdiplusToken);


I Hope to be useful.

LUCINDO MORA.
E-MAIL: NOSPAM_lucindom@gmail.com

zn-soft

  • Guest
Re: Save Screen in JPG file - Grabar Pantalla en Archivo JPG
« Reply #1 on: November 15, 2012, 05:10:35 am »
sorry for necroposting, but how to use IMAGECODECINFO class in pellesC, i dont find any sources

CommonTater

  • Guest
Re: Save Screen in JPG file - Grabar Pantalla en Archivo JPG
« Reply #2 on: November 15, 2012, 05:48:58 am »
sorry for necroposting, but how to use IMAGECODECINFO class in pellesC, i dont find any sources

It's not a class ... it's a struct (structure) that receives information about the image codecs (encoder decoder) on a system.

Code: [Select]
  IMAGECODECINFO *pImageCodecInfo = NULL;        // pointer to IMAGECODECINFO struct.
           
   GdipGetImageEncodersSize(&num, &size);            //  How many and how big?
   if (size == 0)
      return -1;   // Failure

   pImageCodecInfo = malloc(size);                       // get memory for the array
   if (pImageCodecInfo == NULL)
      return -1;   // Failure

   GdipGetImageEncoders(num, size, pImageCodecInfo);   // get the array of IMAGECODECINFO structs

   for (UINT j = 0; j < num; ++j)
   {
      if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0)     // find the right codec
      {
         *pClsid = pImageCodecInfo[j].Clsid;                               // return it's CLSID
         free(pImageCodecInfo);                                               // release memory
         return j;   // Success                                                // huza! it worked.
      }
   }

Now, for clarity... since you used the word "Class" here... you do understand that C and C++ are two different languages?  Pelles C doesn't do C++ ....