示例#1
0
 /// <summary>
 ///     Updates the bitmap image with the image from the <paramref name="bitmap" />.
 /// </summary>
 /// <param name="bitmap">The bitmap.</param>
 protected void UpdateBitmap(Bitmap bitmap)
 {
     try
     {
         this.Bitmap = OLE.GetIPictureDispFromBitmap(bitmap) as IPictureDisp;
     }
     catch (Exception e)
     {
         if (MinerRuntimeEnvironment.IsUserInterfaceSupported)
         {
             Log.Error("Error Updating Bitmap " + this.Name, e);
         }
         else
         {
             Log.Error(e);
         }
     }
 }
示例#2
0
        /// <summary>
        ///     Updates the bitmap image with the image from the <paramref name="stream" />.
        /// </summary>
        /// <param name="stream">Stream of bitmap to load.</param>
        protected void UpdateBitmap(Stream stream)
        {
            try
            {
                Bitmap bitmap = new Bitmap(stream);
                bitmap.MakeTransparent(bitmap.GetPixel(0, 0));

                this.Bitmap = OLE.GetIPictureDispFromBitmap(bitmap) as IPictureDisp;
            }
            catch (Exception e)
            {
                if (MinerRuntimeEnvironment.IsUserInterfaceSupported)
                {
                    Log.Error("Error Updating Bitmap " + this.Name, e);
                }
                else
                {
                    Log.Error(e);
                }
            }
        }
        protected override void PostEntryStep()
        {
            // ReSharper disable UseIndexedProperty
            // ReSharper disable CSharpWarnings::CS0612
            var geoFeatureLayer = Layer as IGeoFeatureLayer;

            if (geoFeatureLayer != null)
            {
                IFeatureRenderer featureRenderer = geoFeatureLayer.Renderer;
                var uniqueValueRenderer          = featureRenderer as IUniqueValueRenderer;
                var displayTable = geoFeatureLayer as IDisplayTable;

                if ((displayTable != null) && (uniqueValueRenderer != null) && (geoFeatureLayer.FeatureClass != null))
                {
                    while (_imageToAdd.Count >= 1)
                    {
                        var    element    = _imageToAdd.ElementAt(0);
                        string classValue = element.Key;
                        Image  image      = element.Value;

                        if (!string.IsNullOrEmpty(classValue))
                        {
                            string  label        = string.Empty;
                            ISymbol markerSymbol = null;

                            if (image != null)
                            {
                                image = MakeTransparant.ApplySrc(image as Bitmap);
                                int size     = Math.Min(image.Width, image.Height) * 4;
                                var imageDst = new Bitmap(size, size);

                                using (Graphics graphics = Graphics.FromImage(imageDst))
                                {
                                    graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                                    graphics.SmoothingMode      = SmoothingMode.HighQuality;
                                    graphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                                    graphics.CompositingQuality = CompositingQuality.HighQuality;

                                    var sRectangle = new Rectangle(0, 0, image.Width, image.Height);
                                    var dRectangle = new Rectangle(0, 0, size, size);
                                    graphics.DrawImage(image, dRectangle, sRectangle, GraphicsUnit.Pixel);
                                }

                                imageDst = MakeTransparant.ApplyDst(imageDst);
                                // ReSharper disable CSharpWarnings::CS0618

                                markerSymbol = new PictureMarkerSymbolClass
                                {
                                    Size = Math.Min(image.Width, image.Height),
                                    BitmapTransparencyColor = Converter.ToRGBColor(Color.White),
                                    Picture = OLE.GetIPictureDispFromBitmap(imageDst) as IPictureDisp
                                };
                            }

                            // ReSharper restore CSharpWarnings::CS0618
                            if (!string.IsNullOrEmpty(classValue))
                            {
                                string[] splitSign = classValue.Split('/');

                                if (splitSign.Length >= 1)
                                {
                                    string   sign       = splitSign[splitSign.Length - 1];
                                    string[] splitLabel = sign.Split('.');

                                    if (splitLabel.Length >= 1)
                                    {
                                        label = splitLabel[0];
                                    }
                                }
                            }

                            if (markerSymbol == null)
                            {
                                markerSymbol = uniqueValueRenderer.DefaultSymbol;
                            }

                            uniqueValueRenderer.AddValue(classValue, FieldNames[0], markerSymbol);
                            uniqueValueRenderer.set_Label(classValue, label);
                            uniqueValueRenderer.set_Symbol(classValue, markerSymbol);
                            _addedImage = true;
                        }

                        _imageToAdd.Remove(classValue);
                    }

                    if ((_featureCursor == null) || (_feature == null))
                    {
                        _featureCursor = displayTable.SearchDisplayTable(null, false) as IFeatureCursor;
                    }

                    if (_featureCursor != null)
                    {
                        _feature = _featureCursor.NextFeature();
                        IFields fields     = _featureCursor.Fields;
                        int     fieldIndex = fields.FindField(FieldNames[0]);

                        while ((_feature != null) && ((_getImageThread == null) || (!_getImageThread.IsAlive)))
                        {
                            // Test to see if this value was added
                            // to the renderer. If not, add it.
                            var  classValue = _feature.get_Value(fieldIndex) as string;
                            bool valFound   = false;

                            for (int i = 0; i <= uniqueValueRenderer.ValueCount - 1; i++)
                            {
                                if (uniqueValueRenderer.get_Value(i) == classValue)
                                {
                                    // Exit the loop if the value was found.
                                    valFound = true;
                                    break;
                                }
                            }

                            // If the value was not found, it is new and it will be added.
                            if (!valFound)
                            {
                                _getImageThread = new Thread(GetImage);
                                _getImageThread.Start(classValue);
                            }
                            else
                            {
                                _feature = _featureCursor.NextFeature();
                            }
                        }

                        geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer;
                    }

                    if ((_feature == null) && _addedImage)
                    {
                        IActiveView activeView = ArcUtils.ActiveView;

                        if (activeView != null)
                        {
                            activeView.ContentsChanged();
                            _addedImage = false;
                        }
                    }
                }
            }

            // ReSharper restore CSharpWarnings::CS0612
            // ReSharper restore UseIndexedProperty
        }