How to set output image quality


SummaryThe 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 just 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.

Development licensing Deployment licensing
Engine Developer Kit ArcView
ArcView ArcEditor
ArcEditor ArcInfo
ArcInfo Engine Runtime

Additional Requirements
  • The code in this task requires that your project include references to the esriDisplay, Carto, and Output assemblies.

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.
 

[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 pagelayout.
*/
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 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