This document is archived and information here might be outdated.  Recommended version.


How to set output image quality (ArcObjects .NET 10.5 SDK)

How to set output image quality


Summary
The information in this topic is intended for those who are customizing or extending the printing pipeline and need fine grained control over the steps of the output process. For most cases where you need to output a map or page layout, you should print via the PrintAndExport class (Carto library). When printing or exporting via the PrintAndExport class, the Output Image Quality is automatically gathered from the Export or Printer object's ResampleRatio property and applied to the active view. If your application does not use the PrintAndExport class, follow the steps in this topic to set the output image quality.
The following function shows how to properly set the output image quality (raster resampling ratio) for a given active view. The output image quality should be set before exporting or printing at the given output image quality. For the sake of consistency, a developer should always retain the original resampling ratio before changing it, and set it back to the original resampling ratio after finishing the export or print task.

Setting output image quality

The following code example uses an IActiveView and a ResampleRatio (resampling ratio). The resampling ratio works the opposite way that you would expect. A value of 1 is the least resampling and therefore, gives the best output image quality.
  1. Obtain the IActiveView for the output image quality you want to modify. This can be a map or page layout.
  2. Call the following function, passing the ActiveView in question with the desired resampling ratio (an integer value from 1 to 5, 1 being the highest quality and 5 being the lowest quality.
[C#]
private void SetOutputQuality(IActiveView docActiveView, long iResampleRatio)
{
    /* This function sets the OutputImageQuality for the active view. If the active view is a pagelayout, then
     * it must also set the output image quality for each of the maps in the page layout.
     */
    IGraphicsContainer docGraphicsContainer;
    IElement docElement;
    IOutputRasterSettings docOutputRasterSettings;
    IMapFrame docMapFrame;
    IActiveView tmpActiveView;
    if (docActiveView is IMap)
    {
        docOutputRasterSettings=docActiveView.ScreenDisplay.DisplayTransformation
            as IOutputRasterSettings;
        docOutputRasterSettings.ResampleRatio=(int)iResampleRatio;
    }
    else if (docActiveView is IPageLayout)
    {
        //Assign ResampleRatio for the PageLayout
        docOutputRasterSettings=docActiveView.ScreenDisplay.DisplayTransformation
            as IOutputRasterSettings;
        docOutputRasterSettings.ResampleRatio=(int)iResampleRatio;
        //and assign ResampleRatio to the maps in the PageLayout.
        docGraphicsContainer=docActiveView as IGraphicsContainer;
        docGraphicsContainer.Reset();
        docElement=docGraphicsContainer.Next();
        while (docElement != null)
        {
            if (docElement is IMapFrame)
            {
                docMapFrame=docElement as IMapFrame;
                tmpActiveView=docMapFrame.Map as IActiveView;
                docOutputRasterSettings =
                    tmpActiveView.ScreenDisplay.DisplayTransformation as
                    IOutputRasterSettings;
                docOutputRasterSettings.ResampleRatio=(int)iResampleRatio;
            }
            docElement=docGraphicsContainer.Next();
        }
        docMapFrame=null;
        docGraphicsContainer=null;
        tmpActiveView=null;
    }
    docOutputRasterSettings=null;
}
[VB.NET]
Private Sub SetOutputQuality(ByVal docActiveView As IActiveView, ByVal iResampleRatio As Long)
    Dim docGraphicsContainer As IGraphicsContainer
    Dim docElement As IElement
    Dim docOutputRasterSettings As IOutputRasterSettings
    Dim docMapFrame As IMapFrame
    Dim tmpActiveView As IActiveView
    If TypeOf docActiveView Is IMap Then
        docOutputRasterSettings=docActiveView.ScreenDisplay.DisplayTransformation
        docOutputRasterSettings.ResampleRatio=iResampleRatio
    ElseIf TypeOf docActiveView Is IPageLayout Then
        'Assign ResampleRatio for PageLayout
        docOutputRasterSettings=docActiveView.ScreenDisplay.DisplayTransformation
        docOutputRasterSettings.ResampleRatio=iResampleRatio
        'and assign ResampleRatio to the maps in the PageLayout.
        docGraphicsContainer=docActiveView
        docGraphicsContainer.Reset()
        docElement=docGraphicsContainer.Next
        Do While Not docElement Is Nothing
            If TypeOf docElement Is IMapFrame Then
                docMapFrame=docElement
                tmpActiveView=docMapFrame.Map
                docOutputRasterSettings=tmpActiveView.ScreenDisplay.DisplayTransformation
                docOutputRasterSettings.ResampleRatio=iResampleRatio
            End If
            docElement=docGraphicsContainer.Next
        Loop
        docMapFrame=Nothing
        docGraphicsContainer=Nothing
        tmpActiveView=Nothing
    End If
    docOutputRasterSettings=Nothing
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
Engine Developer Kit: Military Analyst ArcGIS for Desktop Basic
ArcGIS for Desktop Basic ArcGIS for Desktop Standard
ArcGIS for Desktop Standard ArcGIS for Desktop Advanced
ArcGIS for Desktop Advanced Engine