0

I have a task to convert dimension feature into image with ArcObjects.

I need to get real image that I see in ArcMap (with right size and spatial reference, of course) instead of turning feature into raster by values of some field.

Is it possible to perform feature-to-image conversion with ArcObjects?

I need solution applicable to just dimension feature class, not to layer on the map.

It seems that the IDimensionGraphic interface should be used. But I don't understand what arguments should be passed to its Draw method.

2 Answers 2

1

Not so long ago I have done something like this with ExportTIFF. You can load the feature to map, zoom to it and then do sth. like this:

ExportTIFF docExport = new ExportTIFFClass();
(docExport as IExport).Resolution = (short)iOutputResolution;

(docExport as IExport).PixelBounds = PixelBoundsEnv;
(docExport as IExport).ExportFileName = sOutputDir + ...

(docExport as IExportTIFF).GeoTiff = true;
(docExport as IWorldFileSettings).MapExtent = docMapExtEnv;
(docExport as IWorldFileSettings).OutputWorldFile = true;

if (docExport is IExportImage)
{
    (docExport as IExportImage).ImageType = esriExportImageType.esriExportImageTypeIndexed;
   if (docActiveView.ScreenDisplay is IScreenDisplay2)
   {
        IColor col = new RgbColorClass();
        col.RGB=(docActiveView.ScreenDisplay as IScreenDisplay2).BackgroundRGB;
        (docExport as IExportImage).BackgroundColor = col;
   }
}
long hdc = (docExport as IExport).StartExporting();

IEnvelope dummy = null;
docActiveView.Output((int)hdc, (System.Int16)((docExport as IExport).Resolution), ref exportRECT, docMapExtEnv, null);

(docExport as IExport).FinishExporting();
(docExport as IExport).Cleanup();
1
  • Thank you for your answer. Unfortunately this code won't work without document (and thereby without map), for example, in geoprocessing function in background mode. I need solution applicable to just dimension feature class, not to layer on the map. I've updated my question to reflect this requirement.
    – Maxim
    Commented Mar 11, 2016 at 4:58
1

IDimensionGraphic.Draw requires an ITransformation and hDC, a device context.

The device context can be obtained using the win32 method GetDC, or as it says for IDisplay.StartDrawing,

call IDisplay::StartDrawing with a value of 0 for the hDC as this will automatically use the Windows API function GetDC to populate IScreenDisplay::WindowDC with the hDC of the main display

This might also work for IDimensionGraphic::Draw. It's worth a try.

1
  • Thank you. Can you provide code of method to save dimension feature into image? Something like DimensionToImage(IDimensionFeature feature, string filePath) { ... }
    – Maxim
    Commented Mar 17, 2016 at 4:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.