Example #1
0
        static void HandleMapNewTileAvailable(MapViewport map, Graphics g, Envelope box, Image bm, int sourceWidth, int sourceHeight, ImageAttributes imageAttributes)
        {
            try
            {
                var min = map.WorldToImage(box.Min());
                var max = map.WorldToImage(box.Max());

                min = new PointF((float)Math.Round(min.X), (float)Math.Round(min.Y));
                max = new PointF((float)Math.Round(max.X), (float)Math.Round(max.Y));

                using (var ia = (ImageAttributes)imageAttributes.Clone())
                {
                    g.DrawImage(bm,
                                new Rectangle((int)min.X, (int)max.Y, (int)(max.X - min.X), (int)(min.Y - max.Y)),
                                0, 0,
                                sourceWidth, sourceHeight,
                                GraphicsUnit.Pixel,
                                ia);
                }

                // g.Dispose();
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                //this can be a GDI+ Hell Exception...
            }
        }
Example #2
0
        /// <summary>
        /// Gets the manipulation of the colors in an image to an effect.
        /// </summary>
        /// <param name="threshold">Effect type.</param>
        /// <returns>
        /// A <see cref="T:System.Drawing.Imaging.ImageAttributes" /> object that contains the information about how bitmap colors are manipulated.
        /// </returns>
        public static ImageAttributes GetImageAttributesFromOpacityValueEffect(float threshold)
        {
            ImageAttributes imageAttributes;
            ImageAttributes tempImageAttributes = null;

            try
            {
                tempImageAttributes = new ImageAttributes();
                tempImageAttributes.SetColorMatrix(new ColorMatrix {
                    Matrix33 = threshold / 100.0f
                });
                imageAttributes = (ImageAttributes)tempImageAttributes.Clone();
            }
            finally
            {
                if (tempImageAttributes != null)
                {
                    tempImageAttributes.Dispose();
                }
            }

            return(imageAttributes);
        }
Example #3
0
        /// <summary>
        /// Gets the manipulation of the colors in an image to an effect.
        /// </summary>
        /// <param name="effect">Effect type.</param>
        /// <returns>
        /// A <see cref="T:System.Drawing.Imaging.ImageAttributes" /> object that contains the information about how bitmap colors are manipulated.
        /// </returns>
        public static ImageAttributes GetImageAttributesFromEffect(KnownEffectType effect)
        {
            var newColorMatrix = new ColorMatrix();

            switch (effect)
            {
            case KnownEffectType.None:
                break;

            case KnownEffectType.Disabled:
                newColorMatrix = DisabledColorMatrix;
                break;

            case KnownEffectType.GrayScale:
                newColorMatrix = GrayScaleColorMatrix;
                break;

            case KnownEffectType.GrayScaleRed:
                newColorMatrix = GrayScaleRedColorMatrix;
                break;

            case KnownEffectType.GrayScaleGreen:
                newColorMatrix = GrayScaleGreenColorMatrix;
                break;

            case KnownEffectType.Brightness:
                newColorMatrix = BrightnessColorMatrix;
                break;

            case KnownEffectType.MoreBrightness:
                newColorMatrix = MoreBrightnessColorMatrix;
                break;

            case KnownEffectType.Dark:
                newColorMatrix = DarkColorMatrix;
                break;

            case KnownEffectType.MoreDark:
                newColorMatrix = MoreDarkColorMatrix;
                break;

            case KnownEffectType.GrayScaleBlue:
                newColorMatrix = GrayScaleBlueColorMatrix;
                break;

            case KnownEffectType.OpacityPercent05:
                newColorMatrix.Matrix33 = 0.05f;
                break;

            case KnownEffectType.OpacityPercent10:
                newColorMatrix.Matrix33 = 0.10f;
                break;

            case KnownEffectType.OpacityPercent20:
                newColorMatrix.Matrix33 = 0.20f;
                break;

            case KnownEffectType.OpacityPercent30:
                newColorMatrix.Matrix33 = 0.30f;
                break;

            case KnownEffectType.OpacityPercent40:
                newColorMatrix.Matrix33 = 0.40f;
                break;

            case KnownEffectType.OpacityPercent50:
                newColorMatrix.Matrix33 = 0.50f;
                break;

            case KnownEffectType.OpacityPercent60:
                newColorMatrix.Matrix33 = 0.60f;
                break;

            case KnownEffectType.OpacityPercent70:
                newColorMatrix.Matrix33 = 0.70f;
                break;

            case KnownEffectType.OpacityPercent80:
                newColorMatrix.Matrix33 = 0.80f;
                break;

            case KnownEffectType.OpacityPercent90:
                newColorMatrix.Matrix33 = 0.90f;
                break;
            }

            ImageAttributes imageAttributes;
            ImageAttributes tempImageAttributes = null;

            try
            {
                tempImageAttributes = new ImageAttributes();
                tempImageAttributes.SetColorMatrix(newColorMatrix);
                imageAttributes = (ImageAttributes)tempImageAttributes.Clone();
            }
            finally
            {
                if (tempImageAttributes != null)
                {
                    tempImageAttributes.Dispose();
                }
            }

            return(imageAttributes);
        }