Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Friday, May 11, 2012 7:17:09 AM(UTC)

Ryan  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

I've seen some slight confusion around adjusting the FileFormats in the Save/Convert Dialogues for the CDLL API. So I’m going to post some example code to help clarify.

In order to adjust this you need to set some properties of the SAVEDLGPARAMS that’s passed to the DLG call. You need to adjust the pFileFormats and the uFileFormatsCount,
pFileFormats takes  an array of the structure FILESAVEFORMAT, you want one of these structures for each format you wish to support.

Similarly each FILESAVEFORMAT can support a number of BPPs and Sub Formats.  pFileSaveFormatBpp of FILESAVEFORMAT takes an array of FILESAVEFORMATBPP for this exact reason.  With this structure you can set the supported BPPs as well as the supported SubFormats.

You can find a list of Format/Subformat constants as well as the supported BPP here.


Now for some example code.. Here is a basic Save Method you might see in one of our demos.



L_INT SaveBitmap(HWND hWnd)

{
   LPCHILDDATA   pData;
   OPENFILENAME  SaveFileName;
   SAVEDLGPARAMS FSParm;
   L_TCHAR        szBuffer[MAX_PATH];
   L_INT         nRet;

   memset(&SaveFileName, 0, sizeof(OPENFILENAME));
   memset(&FSParm, 0, sizeof(SAVEDLGPARAMS));
   FSParm.uStructSize = sizeof(SAVEDLGPARAMS);
   memset(szBuffer, 0, sizeof(szBuffer));

   pData = (LPCHILDDATA) L_GETWINDOWLONGPTR(hWnd, GWLP_USERDATA);

   FSParm.nQFactor      = 2;
   FSParm.pBitmap       = &pData->Bitmap;
   FSParm.nBitsPerPixel = pData->Bitmap.BitsPerPixel;
   FSParm.uDlgFlags     =  DLG_SAVE_AUTOPROCESS |
                           DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE|
                           DLG_SAVE_AUTOPROCESS  |
                           DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS|
                           DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS|
                           DLG_SAVE_SHOW_FILEOPTIONS_STAMP|
                           DLG_SAVE_SHOW_FILEOPTIONS_PROGRESSIVE |
                           DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR;   

   SaveFileName.lStructSize       = sizeof(OPENFILENAME);
   SaveFileName.lpstrInitialDir   = NULL;
   SaveFileName.lpstrTitle        = TEXT("Save As");
   SaveFileName.lpstrFile         = szBuffer;
   SaveFileName.nMaxFile          = sizeof(szBuffer)/sizeof(L_TCHAR);
   SaveFileName.lpstrFileTitle    = FSParm.szFileName;
   SaveFileName.nMaxFileTitle     = sizeof(FSParm.szFileName)/sizeof(L_TCHAR);
   SaveFileName.nFileOffset       = 0;
   SaveFileName.Flags             = 0;

   nRet = L_DlgSave (hWnd, &SaveFileName, &FSParm);
   if (nRet <= 0)
   {
      memset(szBuffer, 0, sizeof(szBuffer));
      wsprintf(szBuffer, TEXT("Can not save file,\nError code = %d\n"), nRet);
      MessageBox(hWnd, szBuffer, TEXT("Error!"), MB_OK);
   }

   return SUCCESS;
}




The code above is going to default and allow users to save as any of the supported formats/subforamts that LEADTOOLS currently supports. As pFileFormats as never being set.

Now you can add the following. This will set the Dialogue so that only JPEG is available. And only at 24 and 8 BPP with Lossless compression or YUV 4:4:4 or YUV 4:0:0.


  
   FILESAVEFORMAT SaveFormat;
   FILESAVEFORMATBPP SaveBPP[2];

   SaveBPP[0].uStructSize = sizeof(FILESAVEFORMATBPP);
   SaveBPP[0].nFormatBpp = 24;
   SaveBPP[0].uSubFormats = DLG_FF_SAVE_SUB_JPEG24_YUV_444 | DLG_FF_SAVE_SUB_JPEG24_LOSSLESS;
   SaveBPP[1].uStructSize = sizeof(FILESAVEFORMATBPP);
   SaveBPP[1].nFormatBpp = 8;
   SaveBPP[1].uSubFormats = DLG_FF_SAVE_SUB_JPEG8_YUV_400 | DLG_FF_SAVE_SUB_JPEG8_LOSSLESS;

   SaveFormat.uStructSize = sizeof(FILESAVEFORMATBPP);
   SaveFormat.nFormat = DLG_FF_SAVE_JPEG;
   SaveFormat.nBppCount = 2;
   SaveFormat.pFileSaveFormatBpp = SaveBPP;

   FSParm.pFileFormats = &SaveFormat;
   FSParm.uFileFormatsCount = 1;
  


 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.102 seconds.