Bit Depth setting for Layout Export to PNG

671
5
Jump to solution
07-30-2020 06:41 AM
Sai_PhaneendraPoludasu2
New Contributor III

Hi,

I am using a similar snippet of code to export a layout to PNG format. https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Layouts#export-a-map-frame-to-jpg.

When I export the layout to JPEG the bit depth is 24 with following setting

JPEGColorMode = JPEGColorMode.TwentyFourBitTrueColor

whereas when I export it to PNG with same setting(ColorMode instead of JPEGColorMode) would export an image with a bit depth '32'.

How can I export a layout to a 24 bit PNG ?

Thanks,
Sai

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Sai,

 I duplicated the problem with version 2.4 and 2.4.2.  It looks like the bit depth is 32 instead of 24.  I then tried the same Add-in with 2.5 and it worked as expected.  So it appears that the problem has been fixed with 2.5.

View solution in original post

0 Kudos
5 Replies
UmaHarano
Esri Regular Contributor

I tested this in Pro 2.6. I don't see this issue.  This is the code snippet I am using. (below). I checked the generated png in Visual Studio - it was 24 bit.

 QueuedTask.Run(() => {
        var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault().GetLayout();
        //Export a map frame to JPG.

        PNGFormat png = new PNGFormat
        {
          HasWorldFile = true,
          Resolution = 300,
          OutputFileName = @"C:\temp\layout.png",
          ColorMode = ColorMode.TwentyFourBitTrueColor,
          Height = 800,
          Width = 1200
        };

        //Reference the map frame
        //MapFrame mf = layout.FindElement("MyMapFrame") as MapFrame;

        //Export on the worker thread

        //Check to see if the path is valid and export
        if (png.ValidateOutputFilePath())
        {
          layout.Export(png);  //Export the map frame to JPG
        }

      });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
Sai_PhaneendraPoludasu2
New Contributor III

Hi Uma,

Thanks for your response. I am using Pro 2.4 and after your response I modified the sample and tested it again and I still see the same issue.

Community sample used: arcgis-pro-sdk-community-samples/Layouts/LayoutMapSeries at master · Esri/arcgis-pro-sdk-community-s... 

Modified the below mentioned command to export PNG instead of PDF

public ICommand ExportMapSeriesItem
    {
      get
      {
        return new RelayCommand(async () =>
        {
          try
          {
            // Reference a layoutitem in a project by name
            LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(SelectedMapSeriesItem?.LayoutName));
            if (layoutItem != null)
            {
              // Create the log file and write the current Folder-Connection's to it
              SaveItemDialog saveDialog = new SaveItemDialog();
              saveDialog.Title = "Export the current selected map series item";
              saveDialog.OverwritePrompt = true;
              saveDialog.DefaultExt = "png";

              // If the save dialog was not dismissed, create the file
              if (saveDialog.ShowDialog() == true)
              {
                await QueuedTask.Run(() =>
                {
                  Layout layout = layoutItem.GetLayout();
                  if (layout == null)
                    return;
                    // Create PDF format with appropriate settings
                    PNGFormat png = new PNGFormat()
                    {
                        Resolution = 300,
                        ColorMode = ColorMode.TwentyFourBitTrueColor,
                        OutputFileName = saveDialog.FilePath
                    };
                  if (PDF.ValidateOutputFilePath())
                  {
                    layout.Export(png);
                  }
                });

              }
            }
          }
          catch (Exception ex)
          {
            MessageBox.Show($@"Error in create layout: {ex}");
          }
        }, () => SelectedMapSeriesItem != null);
      }
    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Could you please check and let me know if this is an issue with Pro 2.4 maybe ?

Regards,
Sai

0 Kudos
Sai_PhaneendraPoludasu2
New Contributor III

Uma Harano‌ I have created a sample after setting up Pro 2.6 and it is working fine, whereas it cannot export a 24 bit PNG in Pro 2.4. In both the versions, JPEG export works fine. Is this a bug with Pro 2.4 ?

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Sai,

 I duplicated the problem with version 2.4 and 2.4.2.  It looks like the bit depth is 32 instead of 24.  I then tried the same Add-in with 2.5 and it worked as expected.  So it appears that the problem has been fixed with 2.5.

0 Kudos
Sai_PhaneendraPoludasu2
New Contributor III

Thanks Wolfgang Kaiser‌ confirming.

0 Kudos