示例#1
0
        public static Bitmap GetThumbnail(int width, int height, string filter, string caption, ImageFormat format, Image b)
        {
            Bitmap source = new Bitmap(b);

            source = new Bitmap(source.GetThumbnailImage(width, height, null, IntPtr.Zero));
            if (format == ImageFormat.Gif)
            {
                source = new OctreeQuantizer(0xff, 8).Quantize(source);
            }
            if ((filter.Length > 0) && filter.ToUpper().StartsWith("SHARPEN"))
            {
                string str     = filter.Remove(0, 7).Trim();
                int    nWeight = (str.Length > 0) ? Convert.ToInt32(str) : 11;
                BitmapFilter.Sharpen(source, nWeight);
            }
            if (caption.Length <= 0)
            {
                return(source);
            }
            using (Graphics graphics = Graphics.FromImage(source))
            {
                StringFormat format2 = new StringFormat();
                format2.Alignment     = StringAlignment.Center;
                format2.LineAlignment = StringAlignment.Center;
                using (Font font = new Font("Arial", 12f))
                {
                    graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                    graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, 0, 0, 0)), 0, source.Height - 20, source.Width, 20);
                    graphics.DrawString(caption, font, Brushes.White, 0f, (float)(source.Height - 20));
                    return(source);
                }
            }
        }
示例#2
0
        public static bool MeanRemoval(Bitmap b, int nWeight /* default to 9*/)
        {
            ConvMatrix m = new ConvMatrix();

            m.SetAll(-1);
            m.Pixel  = nWeight;
            m.Factor = nWeight - 8;

            return(BitmapFilter.Conv3x3(b, m));
        }
示例#3
0
        public static bool Smooth(Bitmap b, int nWeight /* default to 1 */)
        {
            ConvMatrix m = new ConvMatrix();

            m.SetAll(1);
            m.Pixel  = nWeight;
            m.Factor = nWeight + 8;

            return(BitmapFilter.Conv3x3(b, m));
        }
示例#4
0
        public static bool EmbossLaplacian(Bitmap b)
        {
            ConvMatrix m = new ConvMatrix();

            m.SetAll(-1);
            m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 0;
            m.Pixel  = 4;
            m.Offset = 127;

            return(BitmapFilter.Conv3x3(b, m));
        }
示例#5
0
        public static bool Sharpen(Bitmap b, int nWeight /* default to 11*/)
        {
            ConvMatrix m = new ConvMatrix();

            m.SetAll(0);
            m.Pixel  = nWeight;
            m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = -2;
            m.Factor = nWeight - 8;

            return(BitmapFilter.Conv3x3(b, m));
        }
示例#6
0
        public static bool GaussianBlur(Bitmap b, int nWeight /* default to 4*/)
        {
            ConvMatrix m = new ConvMatrix();

            m.SetAll(1);
            m.Pixel  = nWeight;
            m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 2;
            m.Factor = nWeight + 12;

            return(BitmapFilter.Conv3x3(b, m));
        }
示例#7
0
        public static bool EdgeDetectQuick(Bitmap b)
        {
            ConvMatrix m = new ConvMatrix();

            m.TopLeft    = m.TopMid = m.TopRight = -1;
            m.MidLeft    = m.Pixel = m.MidRight = 0;
            m.BottomLeft = m.BottomMid = m.BottomRight = 1;

            m.Offset = 127;

            return(BitmapFilter.Conv3x3(b, m));
        }