Get the Image out from ISymbol using ArcObjects Java

761
2
03-02-2018 06:37 PM
Ranga_Tolapi
Occasional Contributor III

Can someone help me please for the relevant Java code of the below C# function.

I am having trouble to pass the first argument i.e. “hDC” for ISymbol.setupDC method. For variable “g”, I am using Java “java.awt.Graphics2D” class as an equivalent of C# “System.Drawing.Graphics”.

private static Image PointSymbolToImage(ISymbol symbol, Size imageSize) {
        
double (imageSize.Width / 2);
        double 
((imageSize.Height - 1) / 2);


        
IPoint point = new PointClass();
        
point.PutCoords(x, y);


        
Bitmap bmp = new Bitmap(imageSize.Width, imageSize.Height);
        
Graphics g Graphics.FromImage(bmp);


        
symbol.SetupDC(g.GetHdc().ToInt32(), null);
        try 
{
            symbol.Draw(point)
;
        
}
        
catch (System.Exception ) {

        }
        symbol.ResetDC()
;


        
g.Dispose();


        return
(Image) bmp;
}

Esri Development CentersEsri Technical SupportArcObjects SDKArcObjects.NETArcGIS Runtime SDK for Java

0 Kudos
2 Replies
KwasiAsante1
New Contributor III

Hi Ranga, 

you can obtain the hDC from the active viewer of whatever control (MapControl or GlobeControl) you are working with

For MapControl: 

IMapControl.getActiveView.getScreenDisplay.geHDC

For GlobeControl: 

IGlobeControl.getGlobeDisplay.getActiveViewer.getHDC

0 Kudos
Ranga_Tolapi
Occasional Contributor III

Hi Kwasi,

Thanks for your response.

My application has no UI, it's a back end batch job, which should generate the images from ISymbol and save them to the disk.

0 Kudos