How to make Transparent background of   Images

1700
6
Jump to solution
07-03-2012 04:31 AM
AnatoliiTerentiev
Occasional Contributor III
Dear Gurus!
I create pPictureElement as follows:
            ESRI.ArcGIS.Carto.IPictureElement pPictureElement;             pPictureElement = new ESRI.ArcGIS.Carto.PngPictureElementClass();             pPictureElement.ImportPictureFromFile(@"D:\__VS\???????\????? ?????\????? ??????? ??????.png");

How can I do transparent background of images?
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
How we can get a picture with transparent background in PngPictureElementClass item?


It is not a supported behavior, so you can't.  There is no property in the interface that supports this that I have seen.  Graphics generally do not support transparency, while layer symbology does.  Converting the locations to point features and then using a picture marker symbol or Representations with transparency may be your only option.

View solution in original post

0 Kudos
6 Replies
AnatoliiTerentiev
Occasional Contributor III
In attachment - the icon which must be added on the active view  and result of next code:
        private void createPictureElement(Image img)
        {
            ESRI.ArcGIS.Carto.IPictureElement pPictureElement;
            pPictureElement = new ESRI.ArcGIS.Carto.PngPictureElementClass();
            pPictureElement.ImportPictureFromFile(@"D:\__VS\picture.png");

          //  ((IOlePictureElement)pPictureElement).ImportPicture(IPictureDispHost.GetIPictureDispFromPicture(img) as stdole.IPictureDisp);

            ESRI.ArcGIS.Geometry.IEnvelope pEnv = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            Size s = getSizeInMapUnits(new Size(105,75));

            pEnv.PutCoords(mapX, mapY, mapX + s.Width, mapY + s.Height);
            ESRI.ArcGIS.Carto.IElement pElement;
            pElement = pPictureElement as ESRI.ArcGIS.Carto.IElement;
            pElement.Geometry = pEnv;
            ESRI.ArcGIS.Carto.IGraphicsContainer pGraphicContainer;
            pGraphicContainer = axMapControl1.Map as IGraphicsContainer;
            pGraphicContainer.AddElement(pElement, 0);
            ESRI.ArcGIS.Carto.IActiveView pActiveView;
            pActiveView = pGraphicContainer as ESRI.ArcGIS.Carto.IActiveView;
            pActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, pElement, pEnv);
        }

How to remove white background? Any ideas?
0 Kudos
AnatoliiTerentiev
Occasional Contributor III
In attachment i show what is needed. I did this whit GDI - the second figure is made of the first removing the background.
How it can be made in arcgis engine 2010?
0 Kudos
AnatoliiTerentiev
Occasional Contributor III
How we can get a picture with transparent background in PngPictureElementClass item?
0 Kudos
RichardFairhurst
MVP Honored Contributor
How we can get a picture with transparent background in PngPictureElementClass item?


It is not a supported behavior, so you can't.  There is no property in the interface that supports this that I have seen.  Graphics generally do not support transparency, while layer symbology does.  Converting the locations to point features and then using a picture marker symbol or Representations with transparency may be your only option.
0 Kudos
AnatoliiTerentiev
Occasional Contributor III
But can`t you say,  is it also easy to resize and move the symbols as is done with the elements?
0 Kudos
AnatoliiTerentiev
Occasional Contributor III
Problem solved as follows:
        ///<summary>Draw a specified graphic on the map using the supplied colors.</summary>
        ///      
        ///<param name="map">An IMap interface.</param>
        ///<param name="geometry">An IGeometry interface. It can be of the geometry type: esriGeometryPoint, esriGeometryPolyline, or esriGeometryPolygon.</param>
        ///<param name="rgbColor">An IRgbColor interface. The color to draw the geometry.</param>
        ///<param name="outlineRgbColor">An IRgbColor interface. For those geometry's with an outline it will be this color.</param>
        ///      
        ///<remarks>Calling this function will not automatically make the graphics appear in the map area. Refresh the map area after after calling this function with Methods like IActiveView.Refresh or IActiveView.PartialRefresh.</remarks>
        public void AddGraphicToMap(double x, double y)
        {
            ESRI.ArcGIS.Display.IRgbColor rgbColorCls = new ESRI.ArcGIS.Display.RgbColorClass();
            rgbColorCls.Red = 255;
            rgbColorCls.Green = 255;
            rgbColorCls.Blue = 255;

            ESRI.ArcGIS.Geometry.Point p = new ESRI.ArcGIS.Geometry.Point();
            p.X = x;
            p.Y = y;
            ESRI.ArcGIS.Geometry.IGeometry geometry = (IGeometry)p;

            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = (ESRI.ArcGIS.Carto.IGraphicsContainer)axMapControl1.Map; // Explicit Cast
            ESRI.ArcGIS.Carto.IElement element = null;

            IPictureMarkerSymbol MarkerSymbol = new ESRI.ArcGIS.Display.PictureMarkerSymbol();

            MarkerSymbol.Size = 50;
            MarkerSymbol.BitmapTransparencyColor = rgbColorCls;


            MarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, @"D:\__VS\�?конки\Новая папка\�?она пожа�?а с�?ема.bmp");

            ESRI.ArcGIS.Carto.IMarkerElement markerElement = new ESRI.ArcGIS.Carto.MarkerElementClass();
            markerElement.Symbol = MarkerSymbol;
            element = (ESRI.ArcGIS.Carto.IElement)markerElement; // Explicit Cast

            element.Geometry = geometry;
            graphicsContainer.AddElement(element, 0);
            
            IActiveView activeView = axMapControl1.Map as IActiveView;
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, MarkerSymbol, null);            
        }
0 Kudos