0

I request a .PNG from a rest API, store it and create a IRasterLayer.

My problem is I'm trying to draw it to the focus map with the RasterLayer.Draw() method, but does not look like I'm doing it right because literally nothing seem to happen...

I'm using ArcObjects 10.4.1

Here is the code:

            byte[] image = await GetBBoxAsync(endpointUri, accessToken);
            MemoryStream ms = new MemoryStream(image);
            Image i = Image.FromStream(ms);

            i.Save("demo.png");

            IRasterLayer rasterLayer = new RasterLayerClass();
            rasterLayer.CreateFromFilePath("demo.png");

            foreach (ILayer layer in layers)
            {
                // Get a random feature's spatial reference

                rasterLayer.SpatialReference = randomFeature.Shape.SpatialReference;

                break;
            }
            IDisplay display = ArcMap.Document.ActiveView.ScreenDisplay;

            rasterLayer.Draw(ESRI.ArcGIS.esriSystem.esriDrawPhase.esriDPGeography, display, null);
            ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

I'm much new to Raster manipulation in ArcObjects... Am I missing something?

1

Add the layer to the your current map before drawing or refreshing the view.

(ArcMap.Document as IMxDocument).FocusMap.AddLayer(rasterLayer);
  • Worked like a charm. Thanks! – Jose Jun 11 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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