Image Filter : Image « 2D Graphics « C# / C Sharp






Image Filter

       
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections.Specialized;

namespace SuchSofts.OpenImage.Lib.Image
{
    internal class ImageFilter
    {

        public string Types { get; set; }
        public Size MinimumSize { get; set; }
        public Size MaximumSize { get; set; }

        public ImageFilter()
        {
            this.Types = GenerateTypesString();
            this.MinimumSize = new Size(1, 1);
            this.MaximumSize = new Size(int.MaxValue, int.MaxValue);
        }

        public ImageFilter(string types, Size minimumSize, Size maximumSize)
        {
            this.Types = types;
            this.MinimumSize = minimumSize;
            this.MaximumSize = maximumSize;
        }

        public ImageFilter(IList<string> types, Size minimumSize, Size maximumSize)
        {
            this.Types = GenerateTypesString(types);
            this.MinimumSize = minimumSize;
            this.MaximumSize = maximumSize;
        }

        #region Static Memebers

        public static readonly List<string> AllTypes = new List<string> { "jpg", "gif", "png", "bmp","{ALL}" };

        public static string GenerateTypesString()
        {
            return GenerateTypesString(AllTypes);
        }

        public static string GenerateTypesString(IList<string> types)
        {
            if (types.Count == 0)
            {
                return "";
            }

            StringBuilder typesBuilder = new StringBuilder();
            for (int i = 0; i < types.Count - 1; i++)
            {
                typesBuilder.Append(types[i]);
                typesBuilder.Append("|");
                for (int j = i + 1; j < types.Count; j++)
                {
                    if (types[j].Equals(types[i], StringComparison.OrdinalIgnoreCase))
                    {
                        types.RemoveAt(j);
                    }
                }
            }
            typesBuilder.Append(types[types.Count - 1]);
            return typesBuilder.ToString();
        }

        public static string GenerateTypesString(string[] types)
        {
            List<string> typesCollection = new List<String>();
            foreach (string type in types)
            {
                typesCollection.Add(type);
            }
            return GenerateTypesString(typesCollection);
        }

        public static bool IsLeagalTypesString(ref string typesString)
        {
            string[] types = typesString.Split('|');
            if (types.Length == 0)
            {
                return false;
            }
            foreach (string type in types)
            {
                bool notMatch = true;
                foreach (string legalType in AllTypes)
                {
                    if (type.Equals(legalType, StringComparison.OrdinalIgnoreCase))
                    {
                        notMatch = false;
                        break;
                    }
                }
                if (notMatch)
                {
                    return false;
                }
            }
            typesString = GenerateTypesString(types);
            return true;
        }

        #endregion

    }
}

   
    
    
    
    
    
    
  








Related examples in the same category

1.Load Image from an image file with Exception handler
2.Image.FromStream: load image from stream
3.Shrink ImageShrink Image
4.Shear ImageShear Image
5.Clone ImageClone Image
6.Get Image Resolution and Image size and Display sizeGet Image Resolution and Image size and Display size
7.Draw image based on its sizeDraw image based on its size
8.Set image resolution and paint itSet image resolution and paint it
9.Load image and displayLoad image and display
10.Fill Ellipse with image based Texture BrushFill Ellipse with image based Texture Brush
11.Image Save
12.Image Open
13.Thumbnail Image
14.Draw on Pixel-Size Image
15.Draw text on an Image
16.Partial Image Rotate
17.Partial Image Stretch
18.Draw Partial Image
19.Image At Points (Draw part of the image)
20.Image Reflection
21.Image Scale Isotropic
22.Image Scale To Rectangle
23.Center Pixel-Size Image by using Image.Width and Image.Height
24.Center an Image (VerticalResolution, HorizontalResolution)
25.Load image from a URL(Web) and draw it
26.Scribble with Bitmap
27.Image Flipping and Rotating
28.Image.GetThumbnailImage
29.Image Zoom
30.Create Thumbnail
31.Image Resize
32.Get Bitmap Source
33.Get Bytes From BitmapSource
34.Load Image
35.Create Icon from Image
36.Resizes an image
37.Get Gravatar Image
38.Changing image opacity, Resize image, crop image and gray scale image
39.Resize Image
40.Resize image to fit
41.Save Window/Canvas to Image
42.Image Cache
43.Saves the image to a bytes array. Used to store an image into DB.
44.Get the "energy" of a pixel