zeleksonob

.net  ,output raster image from activeview unexpected acting

Discussion created by zeleksonob on May 8, 2014
Latest reply on May 8, 2014 by kenbuja
Hello everybody,   i am trying to export envelop from the active view with specific coords ,
first i zoom to raster res, and then calc the envelop coord in pixels ,
when i trying to output to bmp image its putting the image in realy bad resalution , i have no idea what i did wrong ?
Here my code snippest,

ZoomToRatster:
 private static void Zoom2Raster(IActiveView pActiveView,IEnvelope i_envelop)
        {
            IPnt RatserCellSize = new Pnt();
            List<string> RasterLayers = VI_ArcGIS.VI_ArcGisLayers.GetImageLayers(pActiveView.FocusMap);
            foreach (string layerName in RasterLayers)
            {
                ILayer CurrentLayer = VI_ArcGIS.VI_ArcGisLayers.GetLayer(pActiveView.FocusMap, layerName);
                if (CurrentLayer is RasterLayer)
                {
                    if (CurrentLayer.Valid && CurrentLayer.Visible)
                    {
                        CurrentLayer = CurrentLayer as RasterLayer;

                        Raster CurrentRaster = (Raster)(CurrentLayer as IRasterLayer).Raster;
                        
                      
                        RatserCellSize = (CurrentRaster as IRasterProps).MeanCellSize();
                       VI_ArcGisLayers.SetLayerVisible(pActiveView.FocusMap, "ROI", false);
                       
                    }
                }
            }
            
            // Calculate current center x and y (Geographic units)
            double Cx = (i_envelop.XMin + i_envelop.XMax) / 2;
            double Cy = (i_envelop.YMin + i_envelop.YMax) / 2;
     
            // Calculate current view width and height in geographic units (meters) = Current view in pixels * resolution
            double Dx = (pActiveView.ExportFrame.right - pActiveView.ExportFrame.left)  * RatserCellSize.X;
            double Dy = (pActiveView.ExportFrame.bottom - pActiveView.ExportFrame.top)  * RatserCellSize.Y;
            IEnvelope extent = (IEnvelope)new Envelope();
            extent.PutCoords(Cx - Dx / 2, Cy + Dy / 2, Cx + Dx / 2, Cy - Dy / 2);
            pActiveView.Extent = extent;
            pActiveView.Refresh();
         
          
        }



where it all begins :
   public static bool CreateContextBMPFromEnvelop(IHookHelper hookHelper, IEnvelope expEnvelope,
            System.String pathFileName)
        {
            IActiveView pActiveView = hookHelper.ActiveView;
            ESRI.ArcGIS.Geometry.IEnvelope ContextEnvelope = expEnvelope;
            int extandEnvelopRate = VI_ArcGIS.Properties.Settings.Default.ExtentEnveleopRate;
            double Max = Math.Max(ContextEnvelope.Width, ContextEnvelope.Height);
            ContextEnvelope.Expand((Max * extandEnvelopRate - ContextEnvelope.Width) / 2, (Max * extandEnvelopRate - ContextEnvelope.Height) / 2, false);
           
            try
            {
                CreateContextBMPFromEnvelopHelper(pActiveView, ContextEnvelope, pathFileName);
            }

            catch (Exception ex)
            {
                log.InfoFormat("runDetectionForm_OnPrepareNextFrame, Exception:{0}", ex.Message);
                return false;
            }

            return true;
        }


helper:

      
 private static void CreateContextBMPFromEnvelopHelper(IActiveView i_CurrentActiveView, IEnvelope i_Envelope, string i_Pathname)
        {
            if (i_CurrentActiveView == null)
            {
                throw new NullReferenceException("Unable Load View");
            }
            
            Zoom2Raster(i_CurrentActiveView, i_Envelope);
            tagRECT ExportRECT = new tagRECT();
            IDisplayTransformation DisplayTranformation = i_CurrentActiveView.ScreenDisplay.DisplayTransformation;

            DisplayTranformation.FromMapPoint(i_Envelope.UpperLeft, out ExportRECT.left, out ExportRECT.top);
            DisplayTranformation.FromMapPoint(i_Envelope.LowerRight, out ExportRECT.right, out ExportRECT.bottom);

            ExportRECT.right = (ExportRECT.right - ExportRECT.left) ;
            ExportRECT.bottom = ( ExportRECT.bottom - ExportRECT.top) ;
            ExportRECT.top = 0;
            ExportRECT.left = 0;

            

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(ExportRECT.left, ExportRECT.top,ExportRECT.right,ExportRECT.bottom);
            
            ESRI.ArcGIS.Output.IExport export = new ESRI.ArcGIS.Output.ExportPNGClass();
            export.ExportFileName = i_Pathname;
            export.Resolution = 96;
            export.PixelBounds = envelope;
            System.Int32 hDC = 0;
            
            hDC = export.StartExporting();
            try
            {
             
                i_CurrentActiveView.Output(hDC, (System.Int16)export.Resolution, ref ExportRECT, null, null);
        
            }
            catch (Exception ex)
            {
                throw ex;
            }
      
            export.FinishExporting();
            export.Cleanup();
            


        }

Outcomes