/**/
        /// <summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="originalImagePath">源图路径(物理路径)</param>
        /// <param name="thumbnailPath">缩略图路径(物理路径)</param>
        /// <param name="width">缩略图宽度</param>
        /// <param name="height">缩略图高度</param>
        /// <param name="mode">生成缩略图的方式</param>
        public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
        {
            System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath);

            int towidth  = width;
            int toheight = height;

            int x  = 0;
            int y  = 0;
            int ow = originalImage.Width;
            int oh = originalImage.Height;

            switch (mode)
            {
            case "HW":    //指定高宽缩放(可能变形)
                break;

            case "W":    //指定宽,高按比例
                toheight = originalImage.Height * width / originalImage.Width;
                break;

            case "H":    //指定高,宽按比例
                towidth = originalImage.Width * height / originalImage.Height;
                break;

            case "Cut":    //指定高宽裁减(不变形)
                if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                {
                    oh = originalImage.Height;
                    ow = originalImage.Height * towidth / toheight;
                    y  = 0;
                    x  = (originalImage.Width - ow) / 2;
                }
                else
                {
                    ow = originalImage.Width;
                    oh = originalImage.Width * height / towidth;
                    x  = 0;
                    y  = (originalImage.Height - oh) / 2;
                }
                break;

            default:
                break;
            }

            //新建一个bmp图片
            System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);

            //新建一个画板
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);

            //设置高质量插值法
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

            //设置高质量,低速度呈现平滑程度
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            //清空画布并以透明背景色填充
            g.Clear(System.Drawing.Color.Transparent);

            //在指定位置并且按指定大小绘制原图片的指定部分
            g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight),
                        new System.Drawing.Rectangle(x, y, ow, oh),
                        System.Drawing.GraphicsUnit.Pixel);

            try
            {
                //以jpg格式保存缩略图
                bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (System.Exception e)
            {
                throw e;
            }
            finally
            {
                originalImage.Dispose();
                bitmap.Dispose();
                g.Dispose();
            }
        }

        /**/
        /// <summary>
        /// 在图片上增加文字水印
        /// </summary>
        /// <param name="Path">原服务器图片路径</param>
        /// <param name="Path_sy">生成的带文字水印的图片路径</param>
        public static void AddShuiYinWord(string Path, string Path_sy)
        {
            string addText = "CopyRight(R):Http://www.situational.com.cn";

            System.Drawing.Image    image = System.Drawing.Image.FromFile(Path);
            System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(image);
            g.DrawImage(image, 0, 0, image.Width, image.Height);
            System.Drawing.Font  f = new System.Drawing.Font("Verdana", 16);
            System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

            g.DrawString(addText, f, b, 15, 15);
            g.Dispose();

            image.Save(Path_sy);
            image.Dispose();
        }
Beispiel #2
0
        public void rdbDrawString(System.Drawing.Graphics rdb, System.String str, int x, int y, float fontsize = 13)
        {
            if (fontsize != 13)
            {
                this.Font = new System.Drawing.Font(this.TypeFace, fontsize, this.TypeStyle);
            }
            else
            {
                this.Font = this.rdbFont;
            }


            rdb.DrawString(str, this.Font, new System.Drawing.SolidBrush(System.Drawing.Color.White),
                           x - this.DrawStringOffset.X,
                           y - this.DrawStringOffset.Y);
        }
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs
                                        pevent)
        {
            base.OnPaint(pevent);
            System.Drawing.Graphics g = pevent.Graphics;
            System.Drawing.SizeF    stringsize;
            stringsize = g.MeasureString(Clicks.ToString(), this.Font,

                                         this.Width);

            g.DrawString(Clicks.ToString(), this.Font,
                         System.Drawing.SystemBrushes.ControlText,

                         this.Width - stringsize.Width - 3, this.Height -
                         stringsize.Height - 3);
        }
Beispiel #4
0
        private void _button合并_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_listBoxPics.Items.Count < 2)
                {
                    MessageBox.Show("至少有两张图片!");
                    return;
                }
                var diaryImages = _listBoxPics.Items;
                System.Drawing.Bitmap tempImg = new System.Drawing.Bitmap(1, 10);
                foreach (var diaryImage in diaryImages)
                {
                    Stream imgStream         = File.OpenRead(diaryImage.ToString());
                    System.Drawing.Image img = System.Drawing.Image.FromStream(imgStream);
                    imgStream.Close();

                    //
                    int oldWidth  = tempImg.Width;
                    int oldHeight = tempImg.Height;
                    int newWidth  = img.Width;
                    int newHeight = img.Height;
                    int width     = oldWidth >= newWidth ? oldWidth : newWidth;
                    int height    = oldHeight + newHeight + 35;

                    System.Drawing.Bitmap   bm  = new System.Drawing.Bitmap(width, height);
                    System.Drawing.Graphics gra = System.Drawing.Graphics.FromImage(bm);
                    gra.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                    gra.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.Half;
                    gra.DrawImage(tempImg, 0, 0);
                    gra.DrawString(System.IO.Path.GetFileNameWithoutExtension(diaryImage.ToString()), new System.Drawing.Font("微软雅黑", 15), new System.Drawing.SolidBrush(System.Drawing.Color.Black), 0, oldHeight);
                    gra.DrawImage(img, 0, oldHeight + 25);
                    tempImg = bm;
                }
                System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter   = "图片(*.png)|*.png|图片(*.jpg)|*.jpg";
                sfd.FileName = System.IO.Path.GetFileNameWithoutExtension(_listBoxPics.Items[0].ToString());
                sfd.ShowDialog();
                tempImg.Save(sfd.FileName);
                MessageBox.Show("合并成功!");
                _listBoxPics.Items.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
        }
Beispiel #5
0
        public static byte[] CreateImage(string code)
        {
            byte[]        imageBytes = null;
            System.Random rand       = new System.Random();

            using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(200, 50
                                                                            , System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
                {
                    using (System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Yellow))
                    {
                        using (System.Drawing.SolidBrush b = new System.Drawing.SolidBrush(System.Drawing.Color.Black))
                        {
                            using (System.Drawing.SolidBrush White = new System.Drawing.SolidBrush(System.Drawing.Color.White))
                            {
                                System.Drawing.Rectangle rect =
                                    new System.Drawing.Rectangle(0, 0, 200, 50);
                                int counter = 0;

                                g.DrawRectangle(pen, rect);
                                g.FillRectangle(b, rect);

                                for (int i = 0; i < code.Length; i++)
                                {
                                    g.DrawString(code[i].ToString()
                                                 , new System.Drawing.Font("Georgia", 10 + rand.Next(14, 18))
                                                 , White
                                                 , new System.Drawing.PointF(10 + counter, 10));
                                    counter += 20;
                                }

                                DrawRandomLines(g, rand);

                                using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                                {
                                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                                    imageBytes = ms.ToArray();
                                } // End Using ms
                            }     // End Using White
                        }         // End Using b
                    }             // End Using pen
                }                 // End Using g
            }                     // End Using bitmap

            return(imageBytes);
        }
Beispiel #6
0
        public static System.Drawing.Icon CreateGlyphIcon(Glyphs glyph, int iconWidth = 16, int iconHeight = 16, float emSize = 12, System.Drawing.Color?fontColor = null, System.Drawing.Color?backgroundColor = null)
        {
            using (var b = new System.Drawing.Bitmap(iconWidth, iconHeight))
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b))
                    using (System.Drawing.Brush brush = new System.Drawing.SolidBrush(fontColor ?? defaultFontColor))
                        using (var f = new System.Drawing.Font("Segoe MDL2 Assets", emSize, System.Drawing.FontStyle.Regular))
                            using (var sf = new System.Drawing.StringFormat {
                                Alignment = System.Drawing.StringAlignment.Center, LineAlignment = System.Drawing.StringAlignment.Center
                            })
                            {
                                g.Clear(backgroundColor ?? defaultBackgroundColor);
                                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                                g.DrawString(((char)glyph).ToString(), f, brush, new System.Drawing.Rectangle(0, 0, iconWidth, iconHeight), sf);

                                return(System.Drawing.Icon.FromHandle(b.GetHicon()));
                            }
        }
Beispiel #7
0
        public System.Drawing.Bitmap toImage(int width, int height, int barWidth)
        {
            if ((barWidth > width))
            {
                return(null);
            }
            // Init image output
            System.Drawing.Bitmap   image   = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(image);
            int txtSize = 12;

            // Draw background
            if (_hasBackground)
            {
                graphic.FillRectangle(new System.Drawing.SolidBrush(_backgroundColor.toColor()), 0, 0, width, height);
            }
            // Draw colorbar centering in half the Legend text height
            for (int h = txtSize / 2; h <= (height - txtSize / 2); h++)
            {
                // Compute value & color
                float v = _min + (_max - _min) * h / (height - txtSize);
                //			Color c = mapper.getColor(new Coord3d(0,0,v));
                Color c = _mapper.Color(v);
                //To allow the Color to be a variable independent of the coordinates
                // Draw line
                graphic.DrawLine(new System.Drawing.Pen(new System.Drawing.SolidBrush(c.toColor())), 0, height - h, barWidth, height - h);
            }
            // Contour of bar
            graphic.FillRectangle(new System.Drawing.SolidBrush(_foregroundColor.toColor()), 0, Convert.ToSingle(txtSize / 2), barWidth, height - txtSize);
            // Text annotation
            if (((_provider != null)))
            {
                float[] ticks = _provider.generateTicks(_min, _max);
                float   ypos  = 0;
                string  txt   = null;
                for (int t = 0; t <= ticks.Length - 1; t++)
                {
                    //			ypos = (int)(height-height*((ticks[t]-min)/(max-min)));
                    ypos = txtSize + (height - txtSize - (height - txtSize) * ((ticks[t] - _min) / (_max - _min)));
                    //Making sure that the first and last tick appear in the colorbar
                    txt = _renderer.Format(ticks[t]);
                    graphic.DrawString(txt, new System.Drawing.Font("Arial", txtSize, System.Drawing.GraphicsUnit.Pixel), new System.Drawing.SolidBrush(_foregroundColor.toColor()), barWidth + 1, ypos);
                }
            }
            return(image);
        }
Beispiel #8
0
        /// <summary>
        /// Creates an image of the CustomReportItem's name
        /// </summary>
        private byte[] DrawImage(CustomReportItem customReportItem)
        {
            int width      = 1;     // pixels
            int height     = 1;     // pixels
            int resolution = 75;    // dpi

            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height);
            bitmap.SetResolution(resolution, resolution);

            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
            graphics.PageUnit = System.Drawing.GraphicsUnit.Pixel;

            // Get the Font for the Text
            System.Drawing.Font font = new System.Drawing.Font(System.Drawing.FontFamily.GenericMonospace,
                                                               12, System.Drawing.FontStyle.Regular);

            // Get the Brush for drawing the Text
            System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen);

            // Get the measurements for the image
            System.Drawing.SizeF maxStringSize = graphics.MeasureString(customReportItem.Name, font);
            width  = (int)(maxStringSize.Width + 2 * font.GetHeight(resolution));
            height = (int)(maxStringSize.Height + 2 * font.GetHeight(resolution));

            bitmap.Dispose();
            bitmap = new System.Drawing.Bitmap(width, height);
            bitmap.SetResolution(resolution, resolution);

            graphics.Dispose();
            graphics          = System.Drawing.Graphics.FromImage(bitmap);
            graphics.PageUnit = System.Drawing.GraphicsUnit.Pixel;

            // Draw the text
            graphics.DrawString(customReportItem.Name, font, brush, font.GetHeight(resolution),
                                font.GetHeight(resolution));

            // Create the byte array of the image data
            MemoryStream memoryStream = new MemoryStream();

            bitmap.Save(memoryStream, ImageFormat.Bmp);
            memoryStream.Position = 0;
            byte[] imageData = new byte[memoryStream.Length];
            memoryStream.Read(imageData, 0, imageData.Length);

            return(imageData);
        }
Beispiel #9
0
    protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
    {
        base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, "", errorText, cellStyle,
                   advancedBorderStyle, paintParts);

        var       cellValue        = Convert.IsDBNull(value) ? 0 : Convert.ToDecimal(value);
        const int horizontaloffset = 2;

        var parent = (LagerStatusColumn)this.OwningColumn;
        var fnt    = parent.InheritedStyle.Font;
        var icon   = Properties.Resources.lager;

        if (cellValue == 0)
        {
            icon = Properties.Resources.rest;
        }
        else if (cellValue < 0)
        {
            icon = Properties.Resources.question_white;
        }
        const int vertoffset = 0;

        graphics.DrawIcon(icon, cellBounds.X + horizontaloffset,
                          cellBounds.Y + vertoffset);
        var cellText = formattedValue.ToString();
        var textSize =
            graphics.MeasureString(cellText, fnt);
        //  Calculate the correct color:
        var textColor = parent.InheritedStyle.ForeColor;

        if ((cellState &
             DataGridViewElementStates.Selected) ==
            DataGridViewElementStates.Selected)
        {
            textColor = parent.InheritedStyle.
                        SelectionForeColor;
        }
        // Draw the text:
        using (var brush = new SolidBrush(textColor))
        {
            graphics.DrawString(cellText, fnt, brush,
                                cellBounds.X + icon.Width + 2,
                                cellBounds.Y + 0);
        }
    }
Beispiel #10
0
        /// <summary></summary>
        /// <param name="graphics"></param>
        protected virtual void PaintUsingSystemDrawing(System.Drawing.Graphics graphics)
        {
            graphics.Clear(System.Drawing.Color.CornflowerBlue);

            if (DesignMode)
            {
                using (System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.WhiteSmoke))
                {
                    using (System.Drawing.StringFormat format = new System.Drawing.StringFormat())
                    {
                        format.Alignment     = System.Drawing.StringAlignment.Center;
                        format.LineAlignment = System.Drawing.StringAlignment.Center;

                        graphics.DrawString("Xen WinForms Host Control", Font, brush, ClientRectangle, format);
                    }
                }
            }
        }
Beispiel #11
0
        public MemoryBitmap <Pixel.Alpha8> GetGlyph(char c)
        {
            if (_Glyphs.TryGetValue(c, out var bmp))
            {
                return(bmp);
            }

            _Graphics.Clear(System.Drawing.Color.Transparent);
            _Graphics.DrawString(c.ToString(), _FontSource, System.Drawing.Brushes.White, new System.Drawing.PointF(0, 0));

            bmp = _Bitmap.ToMemoryBitmap(Pixel.Alpha8.Format).OfType <Pixel.Alpha8>();

            // bmp = bmp.CropVisible().Clone();

            _Glyphs[c] = bmp;

            return(bmp);
        }
Beispiel #12
0
        /// <summary>
        /// 建立贴图并添加到缓冲中。
        /// 尽量在第一次绘制之前调用该函数,这样可以避免建立贴图的过程造成游戏的停滞
        /// </summary>
        /// <param name="text">要创建的字符串</param>
        /// <param name="fontName">字体</param>
        /// <returns></returns>
        public Texture2D BuildTexture(string text, string fontName)
        {
            TextKey key = new TextKey(text, fontName);

            if (cache.ContainsKey(key))
            {
                return(null);
            }

            if (!fonts.ContainsKey(fontName))
            {
                Log.Write("error fontName used in BuildTexture");
                return(null);
            }

            System.Drawing.Font font = fonts[fontName];

            System.Drawing.SizeF size = mesureGraphics.MeasureString(text, font);
            int texWidth  = (int)size.Width;
            int texHeight = (int)size.Height;

            System.Drawing.Bitmap   textMap     = new System.Drawing.Bitmap(texWidth, texHeight);
            System.Drawing.Graphics curGraphics = System.Drawing.Graphics.FromImage(textMap);
            curGraphics.DrawString(text, font, System.Drawing.Brushes.White, new System.Drawing.PointF());

            Texture2D texture = new Texture2D(engine.Device, texWidth, texHeight, 1, TextureUsage.None, SurfaceFormat.Color);

            Microsoft.Xna.Framework.Graphics.Color[] data = new Microsoft.Xna.Framework.Graphics.Color[texWidth * texHeight];
            for (int y = 0; y < texHeight; y++)
            {
                for (int x = 0; x < texWidth; x++)
                {
                    data[y * texWidth + x] = ConvertHelper.SysColorToXNAColor(textMap.GetPixel(x, y));
                }
            }

            texture.SetData <Microsoft.Xna.Framework.Graphics.Color>(data);

            cache.Add(key, texture);

            curGraphics.Dispose();

            return(texture);
        }
Beispiel #13
0
        public byte[] CreateImage(string _captchaText)
        {
            byte[] imageBytes = null;

            using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(200, 150, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
                {
                    System.Drawing.Pen        pen  = new System.Drawing.Pen(System.Drawing.Color.Yellow);
                    System.Drawing.Rectangle  rect = new System.Drawing.Rectangle(0, 0, 200, 150);
                    System.Drawing.SolidBrush b    = new System.Drawing.SolidBrush(System.Drawing.Color.DarkKhaki);
                    System.Drawing.SolidBrush blue = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

                    //pen.Dispose
                    // b.Dispose
                    // blue.Dispose


                    int counter = 0;

                    g.DrawRectangle(pen, rect);

                    g.FillRectangle(b, rect);

                    for (int i = 0; i < _captchaText.Length; i++)
                    {
                        g.DrawString(_captchaText[i].ToString()
                                     , new System.Drawing.Font("Verdena", 10 + rand.Next(14, 18)), blue
                                     , new System.Drawing.PointF(10 + counter, 10));
                        counter += 20;
                    }

                    DrawRandomLines(g);

                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                    {
                        bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        imageBytes = ms.ToArray();
                    } // End Using ms
                }     // End Using g
            }         // End Using bitmap

            return(imageBytes);
        }
Beispiel #14
0
        private byte[] RandomSymbol(int number)
        {
            number = number % 360;
            string text = "";

            System.Drawing.Brush brush = null;
            if (number < 60)
            {
                return(null);
            }
            if (number < 120)
            {
                text  = "<120";
                brush = System.Drawing.Brushes.DarkGreen;
            }
            else if (number < 240)
            {
                text  = number.ToString();
                brush = System.Drawing.Brushes.Orange;
            }
            else
            {
                text  = ">240";
                brush = System.Drawing.Brushes.Red;
            }

            System.Drawing.Bitmap     bmp  = new System.Drawing.Bitmap(120, 60);
            System.Drawing.Graphics   g    = System.Drawing.Graphics.FromImage(bmp);
            System.Drawing.RectangleF size = new System.Drawing.RectangleF(0f, 0f, 120f, 60f);
            g.FillRectangle(System.Drawing.Brushes.White, size);
            var sf = new System.Drawing.StringFormat(System.Drawing.StringFormatFlags.NoWrap)
            {
                Alignment = System.Drawing.StringAlignment.Center
            };

            g.DrawString(text, new System.Drawing.Font("Arial", 24), brush, size, sf);
            g.Flush();
            g.Dispose();
            var ms = new System.IO.MemoryStream();

            bmp.MakeTransparent(System.Drawing.Color.White);
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            return(ms.ToArray());
        }
Beispiel #15
0
        /// <summary>
        /// 创建水印文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="text"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="horizontalResolution"></param>
        /// <param name="verticalResolution"></param>
        public static void CreatWotermarkFile(this string fileName, string text, int width, int height, float horizontalResolution, float verticalResolution)
        {
            if (System.IO.File.Exists(fileName))
            {
                return;
            }

            System.Drawing.Bitmap img = new System.Drawing.Bitmap(width, height);
            img.SetResolution(horizontalResolution, verticalResolution);
            img.MakeTransparent();
            using (var gImage = System.Drawing.Graphics.FromImage(img))
            {
                //生成字体
                //var font = new System.Drawing.Font(System.Drawing.SystemFonts.DefaultFont.Name, fpSize, System.Drawing.FontStyle.Bold);
                //var font = new System.Drawing.Font(System.Drawing.SystemFonts.DefaultFont.Name, Convert.ToInt32((img.Width / 50)), System.Drawing.FontStyle.Bold);
                var font = new System.Drawing.Font(System.Drawing.SystemFonts.DefaultFont.Name, width / 50, System.Drawing.FontStyle.Bold);
                //测量文字长度
                var size = gImage.MeasureString(text, font);

                ("水印大小计算结果:size.Width->" + size.Width + " , size.Height ->" + size.Height).WriteToLog();
                //生成一张图片
                using (System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)size.Width + 10, (int)size.Height + 10))
                {
                    using (System.Drawing.Graphics gText = System.Drawing.Graphics.FromImage(image))
                    {
                        //绘制背景
                        gText.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(120, System.Drawing.Color.Black)), 0, 0, image.Width, image.Height);
                        //绘制文字
                        gText.DrawString(text, font, System.Drawing.Brushes.Yellow, 5, 5);

                        ////绘制背景
                        //g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(120, System.Drawing.Color.Black)), (img.Width - size.Width - 50 - 5), ((img.Height / 50) - 5), size.Width + 10, size.Height + 10);
                        ////绘制文字
                        //g.DrawString(Text, font, System.Drawing.Brushes.Yellow, (img.Width - size.Width - 50), (img.Height / 50));
                    }

                    gImage.DrawImage(image, (img.Width - image.Width - 20), (img.Height / 50));
                }
            }
            img.Save(fileName);
            img.Dispose();
            GC.Collect();
        }
Beispiel #16
0
        /// <summary>
        /// 在图片上增加文字水印
        /// </summary>
        /// <param name="Path">原服务器图片路径</param>
        /// <param name="Path_sy">生成的带文字水印的图片路径</param>
        /// <param name="addText">生成的文字</param>
        /// <param name="IsDeleteOld">是否删除旧图片</param>
        public static void AddWater(string Path, string Path_sy, string addText, bool IsDeleteOld)
        {
            System.Drawing.Image    image = System.Drawing.Image.FromFile(Path);
            System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(image);
            g.DrawImage(image, 0, 0, image.Width, image.Height);
            System.Drawing.Font  f = new System.Drawing.Font("Verdana", 16);
            System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.GreenYellow);

            g.DrawString(addText, f, b, 10, 10);
            g.Dispose();

            image.Save(Path_sy);
            image.Dispose();

            if (IsDeleteOld && File.Exists(Path))
            {
                File.Delete(Path);
            }
        }
Beispiel #17
0
        private void DrawViewFrame(System.Drawing.Graphics graphics, string title, RectangleF printRect, int marginFromBorder)
        {
            Rectangle borderRectangle = new Rectangle((int)(printRect.X - marginFromBorder),
                                                      (int)(printRect.Y - marginFromBorder),
                                                      (int)(printRect.Width + 2 * marginFromBorder),
                                                      (int)(printRect.Height + 2 * marginFromBorder));

            // Draws the view title
            System.Drawing.SizeF titleSize = graphics.MeasureString(title, Font);
            graphics.DrawString(title, Font, System.Drawing.Brushes.Black, borderRectangle.Left + borderRectangle.Width / 2 - titleSize.Width / 2, borderRectangle.Top - titleSize.Height);

            // Draws a shadow rectangle
            graphics.FillRectangle(System.Drawing.Brushes.LightGray, borderRectangle.Left + 10, borderRectangle.Top + 10, borderRectangle.Width, borderRectangle.Height);
            graphics.FillRectangle(System.Drawing.Brushes.White, borderRectangle);

            // Draws the border of the viewport
            Pen borderPen = new Pen(System.Drawing.Color.Gray, 1);

            graphics.DrawRectangle(borderPen, borderRectangle);
        }
Beispiel #18
0
        public override System.Drawing.Bitmap Render(System.Drawing.Graphics g, System.Drawing.Bitmap b, params int[] options)
        {
            System.Drawing.Color     bc = DrawingBackColor;
            System.Drawing.Color     fc = DrawingForeColor;
            System.Drawing.Rectangle r  = new System.Drawing.Rectangle()
            {
                Height = b.Height, Width = b.Width
            };
            r.Inflate(-1, -1);
            g.Clear(System.Drawing.Color.White);
            g.FillEllipse(new System.Drawing.SolidBrush(bc), r);
            g.DrawEllipse(new System.Drawing.Pen(fc), r);
            string s = options[0].ToString();

            r.Inflate(s.Length > 1 ? 4 : -4, -2);
            System.Drawing.Font fnt = new System.Drawing.Font("Microsoft Sans Serif", 12, System.Drawing.FontStyle.Bold);
            g.DrawString(s, fnt, new System.Drawing.SolidBrush(fc), r);
            b.MakeTransparent(System.Drawing.Color.White);
            return(b);
        }
Beispiel #19
0
        /// <summary>
        /// Draws a text message with transparent background and returns a texture
        /// </summary>
        /// <returns></returns>
        public static Texture2D DrawString(string message, System.Drawing.Font font)
        {
            // Measure the text with the already instantated measureGraphics object.
            System.Drawing.Size measuredsize = instance.measureGraphics.MeasureString(message, font).ToSize();
            if (measuredsize.Width == 0 || measuredsize.Height == 0)
            {
                return(empty);
            }

            // Create the final bitmap
            using (System.Drawing.Bitmap bmpSurface = new System.Drawing.Bitmap(measuredsize.Width, measuredsize.Height))
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpSurface))
                {
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.High;
                    g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;

                    // Draw the text to the clean bitmap
                    g.Clear(System.Drawing.Color.Transparent);
                    g.DrawString(message, font, instance.fontBrush, System.Drawing.PointF.Empty);

                    System.Drawing.Imaging.BitmapData bmd = bmpSurface.LockBits(new System.Drawing.Rectangle(0, 0, bmpSurface.Width, bmpSurface.Height),
                                                                                System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    int bufferSize = bmd.Height * bmd.Stride;
                    //create data buffer
                    byte[] bytes = new byte[bufferSize];
                    // copy bitmap data into buffer
                    Marshal.Copy(bmd.Scan0, bytes, 0, bytes.Length);

                    // copy our buffer to the texture
                    Texture2D texture = new Texture2D(instance.Game.GraphicsDevice, bmpSurface.Width, bmpSurface.Height, false, SurfaceFormat.Bgra32);
                    texture.SetData(bytes);
                    // unlock the bitmap data
                    bmpSurface.UnlockBits(bmd);

                    return(texture);
                }
            }
        }
Beispiel #20
0
        /// <summary>
        /// 在图片上添加文字水印
        /// </summary>
        /// <param name="syWord">要添加的水印文字</param>
        /// <param name="path">要添加水印的图片路径</param>
        /// <param name="syPath">生成的水印图片存放的位置</param>
        public static void AddWaterWord(string syWord, string path, string syPath)
        {
            System.Drawing.Image image = System.Drawing.Image.FromFile(path);

            //新建一个画板
            System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(image);
            graphic.DrawImage(image, 0, 0, image.Width, image.Height);

            //设置字体
            System.Drawing.Font f = new System.Drawing.Font("Verdana", 12);

            //设置字体颜色
            System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Red);

            graphic.DrawString(syWord, f, b, 110, 150);
            graphic.Dispose();

            //保存文字水印图片
            image.Save(syPath);
            image.Dispose();
        }
        private void DrawRulerNumber(System.Drawing.Graphics grap, int value, int posistion)
        {
            System.Drawing.StringFormat format = new System.Drawing.StringFormat(System.Drawing.StringFormatFlags.MeasureTrailingSpaces);

            System.Drawing.Font font = null;

            if (this.Orientation == RulerOrientationEnum.Vertical)
            {
                format.FormatFlags |= System.Drawing.StringFormatFlags.DirectionVertical;

                font = new System.Drawing.Font("Segoe UI", (float)(this.Width / 3));
            }
            else
            {
                font = new System.Drawing.Font("Segoe UI", (float)(this.Height / 3));
            }

            System.Drawing.SizeF size = grap.MeasureString((value).ToString(), font, 30, format);

            int x = 0;

            int y = 0;

            if (this.Orientation == RulerOrientationEnum.Horizontal)
            {
                x = posistion - (int)size.Width - 3;

                y = (int)this.Height - (int)size.Height;
            }
            else
            {
                x = (int)this.Width - (int)size.Width;

                y = posistion + 5 - (int)size.Height / 2;
            }

            System.Drawing.Point drawAt = new System.Drawing.Point(x, y);

            grap.DrawString(value.ToString(), font, System.Drawing.Brushes.DarkGray, drawAt, format);
        }
Beispiel #22
0
        } // End Sub SetFont

        /// <summary>
        /// Writes a text to the bitmap.
        /// </summary>
        /// <param name="left">The left position of the text to be written.</param>
        /// <param name="top">The top position of the text to be written.</param>
        /// <param name="text">The text to be written.</param>
        private void WriteText(int left, int top, string text)
        {
            //Create a blank image.
            this.DestinationImage = new System.Drawing.Bitmap(this.SourceImage.Width, this.SourceImage.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            //Font titleFont = new Font("Arial Black", 36, FontStyle.Italic, GraphicsUnit.Point);

            // If forgot to specify the font name etc.
            if (TextFont == null)
            {
                TextFont = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point);
            }

            // If forgot to specify color
            if (TextColor.IsEmpty)
            {
                TextColor = System.Drawing.Color.Black;
            }


            // If forgot to specify color
            if (TextBrush == null)
            {
                TextBrush = new System.Drawing.SolidBrush(TextColor);
            }


            //Get the Graphics object of the image to use in drawing.
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(this.DestinationImage))
            {
                //Draw the original image.
                g.DrawImage(this.SourceImage, 0, 0);
                //Used to write smooth text.
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                // float y = top + g.MeasureString(title, TextFont).Height;
                // g.DrawString(body, TextFont, TextBrush, left, y, StringFormat.GenericTypographic);
                g.DrawString(text, TextFont, TextBrush, left, top, System.Drawing.StringFormat.GenericTypographic);
            } // End Using g
        }     // End Sub WriteText
Beispiel #23
0
        private void PrintOutputCanvasLayer(Image canvas, List <Kinect.ObjectsDetection.DetectedObject> objects, int width, int height)
        {
            if (objects != null && objects.Count > 0)
            {
                canvas.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (ThreadStart) delegate()
                {
                    if (bmpOutputLayer == null)
                    {
                        bmpOutputLayer = new System.Drawing.Bitmap(width, height);
                    }
                    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpOutputLayer))
                    {
                        g.Clear(System.Drawing.Color.Transparent);
                        System.Drawing.Pen pen1 = new System.Drawing.Pen(System.Drawing.Color.Blue, 4);
                        System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Color.Aqua, 4);
                        foreach (Kinect.ObjectsDetection.DetectedObject o in objects)
                        {
                            System.Drawing.Point p1 = new System.Drawing.Point(), p2 = new System.Drawing.Point();
                            for (int c = 0; c < o.RelCorners.Length - 1; c++)
                            {
                                p1 = new System.Drawing.Point(o.RelCorners[c].X * width / 100, o.RelCorners[c].Y * height / 100);
                                p2 = new System.Drawing.Point(o.RelCorners[c + 1].X * width / 100, o.RelCorners[c + 1].Y * height / 100);
                                g.DrawLine(pen1, p1, p2);
                            }
                            p1 = p2;
                            p2 = new System.Drawing.Point(o.RelCorners[0].X * width / 100, o.RelCorners[0].Y * height / 100);
                            g.DrawLine(pen2, p1, p2);

                            System.Drawing.Font drawFont        = new System.Drawing.Font("Arial", 30);
                            System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
                            g.DrawString(o.Data, drawFont, drawBrush, o.RelCenter.X * width / 100, o.RelCenter.Y * height / 100);
                        }
                    }


                    canvas.Source = ConvertToBitmapImage(bmpOutputLayer);
                });
            }
        }
        /// <summary>
        /// Gets a color avatar based on user's initials.
        /// </summary>
        /// <param name="name">User´s name</param>
        /// <returns>The user color avatar</returns>
        public byte[] GetColorAvatar(string name)
        {
            var initials = GetInitials(name);
            var bg       = GetAvatarBG(initials);
            var font     = new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 22);

            System.Drawing.Bitmap   img = new System.Drawing.Bitmap(60, 60);
            System.Drawing.Graphics g   = System.Drawing.Graphics.FromImage(img);
            g.FillRectangle(bg, 0, 0, 60, 60);

            var size = g.MeasureString(initials, font);

            g.DrawString(initials,
                         font,
                         System.Drawing.Brushes.White,
                         (float)30 - (size.Width / 2),
                         (float)30 - (size.Height / 2));

            g.Dispose();

            return(ImageToBytes(img));
        }
Beispiel #25
0
        public void setIconOverlayForNewItems(int number)
        {
            if (TaskbarManager.IsPlatformSupported)
            {
                System.Drawing.RectangleF rectF  = new System.Drawing.RectangleF(0, 0, 40, 40);
                System.Drawing.Bitmap     bitmap = new System.Drawing.Bitmap(40, 40, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                System.Drawing.Graphics   g      = System.Drawing.Graphics.FromImage(bitmap);
                g.FillRectangle(System.Drawing.Brushes.DarkBlue, 0, 0, 40, 40);
                g.DrawString(number.ToString(), new System.Drawing.Font("Segoe UI", 20), System.Drawing.Brushes.White, new System.Drawing.PointF(0, 0));

                IntPtr hBitmap = bitmap.GetHbitmap();

                ImageSource wpfBitmap =
                    Imaging.CreateBitmapSourceFromHBitmap(
                        hBitmap, IntPtr.Zero, Int32Rect.Empty,
                        BitmapSizeOptions.FromEmptyOptions());


                System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(bitmap.GetHicon());
                TaskbarManager.Instance.SetOverlayIcon(icon, number.ToString());
            }
        }
        void parser_NotifyIconUpdated(object sender, GoogleDocsNotifier.Events.NotifyIconUpdatedEventArgs e)
        {
            if (e.NumOfUnviewedDocuments > 0)
            {
                System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
                //The original icon for the Google Docs Notifier.
                System.Drawing.Image originalAppIcon =
                    System.Drawing.Icon.ExtractAssociatedIcon(
                        System.Windows.Forms.Application.ExecutablePath).ToBitmap();
                //Create a bitmap and draw the number of unviewed documents on it.
                System.Drawing.Bitmap   bitmap   = new System.Drawing.Bitmap(16, 16);
                System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
                graphics.DrawImage(originalAppIcon, 0, 0, 16, 16);
                graphics.DrawString(e.NumOfUnviewedDocuments.ToString(), new System.Drawing.Font("Helvetica", 6), brush, 3, 3);
                graphics.Save();
                //Convert the bitmap with text to an Icon.
                IntPtr hIcon             = bitmap.GetHicon();
                System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(hIcon);
                trayNotifyIcon.Icon = icon;
                //Dispose the graphics.
                graphics.Dispose();
                trayNotifyIcon.Text = e.NumOfUnviewedDocuments.ToString() + " unread documents";
            }
            else
            {
                trayNotifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);
                trayNotifyIcon.Text = "No unread document";
            }

            //Show the balloon tooltip.
            if (e.IsDisplayTooltip)
            {
                //Title of the balloon tooltip.
                trayNotifyIcon.BalloonTipTitle = e.Title;
                trayNotifyIcon.BalloonTipText  = e.Message;
                trayNotifyIcon.ShowBalloonTip(500);
            }
        }
Beispiel #27
0
        /// <summary>
        /// 在图片上增加文字水印
        /// </summary>
        /// <param name="Path">原服务器图片路径</param>
        /// <param name="Path_sy">生成的带文字水印的图片路径</param>
        /// <param name="waterCharater">水印文字</param>
        /// <param name="xPercent">水印文字与图片左上角X轴的百分比(用小数表示)0~1</param>
        /// <param name="yPercent">水印文字与图片左上角Y轴的百分比(用小数表示)0~1</param>
        /// <param name="charColor">文字颜色System.Color</param>
        public static void AddWater(string Path, string Path_sy, string waterCharater, double xPercent, double yPercent, System.Drawing.Color charColor, string fontFamilyName, int fontSize)
        {
            if (!File.Exists(Path))
            {
                throw new FileNotFoundException("指定路径的文件不存在");
            }
            else
            {
                if (string.IsNullOrEmpty(fontFamilyName))
                {
                    fontFamilyName = "仿宋";
                }
                System.Drawing.Image    image  = System.Drawing.Image.FromFile(Path);
                System.Drawing.Bitmap   bitmap = new System.Drawing.Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                System.Drawing.Graphics g      = System.Drawing.Graphics.FromImage(bitmap);
                g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;// HighQuality;
                g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                g.Clear(System.Drawing.Color.Transparent);

                System.Drawing.Imaging.EncoderParameters parms = new System.Drawing.Imaging.EncoderParameters(1);
                parms.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, ((long)80));
                string extension = System.IO.Path.GetExtension(Path).ToLower();
                System.Drawing.Imaging.ImageCodecInfo imgCodeInfo = GetImageCodeInfo(SetImgType()[extension].ToString());

                g.DrawImage(image, 0, 0, image.Width, image.Height);
                System.Drawing.Font  f = new System.Drawing.Font(fontFamilyName, fontSize);
                System.Drawing.Brush b = new System.Drawing.SolidBrush(charColor);
                float x = (float)Convert.ToDecimal(image.Height * xPercent);
                float y = (float)Convert.ToDecimal(image.Width * yPercent);
                g.DrawString(waterCharater, f, b, x, y);
                g.Dispose();
                //image.Save(Path_sy);
                image.Dispose();
                bitmap.Save(Path_sy, imgCodeInfo, parms);
                bitmap.Dispose();
            }
        }
        protected void GeneraImagen(string Texto)
        {
            imgPass.Visible = false;

            try
            {
                System.IO.FileStream fs    = new System.IO.FileStream(Server.MapPath("~/Forms/UserImg") + "\\" + ImagenBase, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                System.Drawing.Image image = System.Drawing.Image.FromStream(fs);
                //fs.Close();
                System.Drawing.Bitmap     b         = new System.Drawing.Bitmap(image);
                System.Drawing.Graphics   graphics  = System.Drawing.Graphics.FromImage(b);
                System.Drawing.Font       drawFont  = new System.Drawing.Font("Arial", 10);
                System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
                System.Drawing.RectangleF drawRect  = new System.Drawing.RectangleF(Rec_x, Rec_y, Rec_width, Rec_height);
                System.Drawing.Pen        whitePen  = new System.Drawing.Pen(System.Drawing.Color.Transparent);
                graphics.DrawRectangle(whitePen, Rec_x, Rec_y, Rec_width, Rec_height);
                System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
                drawFormat.Alignment       = System.Drawing.StringAlignment.Center;
                drawFormat.LineAlignment   = System.Drawing.StringAlignment.Center;
                graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                graphics.DrawString(Texto, drawFont, drawBrush, drawRect, drawFormat);

                //Para impedir error de GDI+ Generico en el Save se debe de dar permisos de escritura al usuario de ASP.NET
                string Archivo = System.IO.Path.Combine(Server.MapPath("../Reportes/TmpFiles/"), DatosGenerales.GeneraNombreArchivoRnd("Bov_", "png"));
                b.Save(Archivo, image.RawFormat);
                imgPass.ImageUrl = "imgProc.aspx?img=" + System.IO.Path.GetFileName(Archivo);
                imgPass.Visible  = true;
                pnlMsjP.Visible  = false;

                fs.Close();
                image.Dispose();
                //System.IO.File.Delete(Archivo);
            }
            catch (Exception ex)
            {
                lblMsjP.Text = "No se pudo generar la imagen: " + ex.Message;
            }
        }
        protected override void OnPaint(PaintEventArgs args)
        {
            System.Drawing.Rectangle rect = ClientRectangle;
            System.Drawing.Graphics  g    = args.Graphics;

            ProgressBarRenderer.DrawHorizontalBar(g, rect);

            if (Value > 0)
            {
                System.Drawing.Rectangle clip = new System.Drawing.Rectangle(rect.X, rect.Y, (int)System.Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                ProgressBarRenderer.DrawHorizontalChunks(g, clip);
            }

            // Set the progress display text (as either %age or custom text)
            string DisplayProgress = DisplayStyle == (ProgressBarDisplayText.Percentage) ? string.Format(UserHelper.culture, "{0} %", Value) : CustomText;

            using (System.Drawing.Font font = new System.Drawing.Font(System.Drawing.FontFamily.GenericMonospace, 10))
            {
                System.Drawing.SizeF size     = g.MeasureString(DisplayProgress, font);
                System.Drawing.Point location = new System.Drawing.Point((int)((rect.Width / 2) - (size.Width / 2)), (int)((rect.Height / 2) - (size.Height / 2) + 2));
                g.DrawString(DisplayProgress, font, System.Drawing.Brushes.Black, location);
            }
        }
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
        {
            DataRowView drv = source.List[rowNum] as DataRowView;
            string      text;

            if (drv == null)
            {
                text = string.Empty;
            }
            else
            {
                text = drv[this.MappingName].ToString();
            }

            if (htmlFormat)
            {
                string[] transformSections = r.Split(text);
                text = string.Join(" ", transformSections).Replace("\n", " ").Trim();
            }

            g.FillRectangle(backBrush, bounds);
            bounds.Offset(0, 2);
            g.DrawString(text, this.DataGridTableStyle.DataGrid.Font, foreBrush, bounds, System.Drawing.StringFormat.GenericDefault);
        }
        /// <summary>
        /// Draws the control.
        /// </summary>
        /// <param name="g"></param>
        private void Draw(Graphics g)
        {
            Brush bgBrush = new HatchBrush(HatchStyle.DarkDownwardDiagonal, Color.Gray, Color.LightGray);
            g.FillRectangle(bgBrush, 0, 0, THUMB_WIDTH, THUMB_HEIGHT);

            g.DrawImage(thumb, 0, 0);
            g.DrawString(Label, ElementFont, new System.Drawing.SolidBrush(ForeColor), THUMB_WIDTH + 5, 10);
        }
        public virtual void Draw(Graphics g)
        {
            var rect = BoundingRectangle;

            var annLabel = ShowLabel ? ann.Label : "";
            var labelSize = g.MeasureString(annLabel, drawingFont);

            g.DrawString(annLabel, drawingFont, new System.Drawing.SolidBrush(DefaultPen.Color), 
                                  new System.Drawing.PointF 
                                  {
                                      X = rect.X,
                                      Y = rect.Y - labelSize.Height - 5
                                  });
        }
Beispiel #33
0
        public static void PaintUsingSystemDrawing(GdiGraphics graphics, string text, GdiRectangle clientRectangle)
        {
            graphics.Clear(GdiColor.CornflowerBlue);

            using (var brush = new GdiSolidBrush(GdiColor.Black))
            using (var format = new GdiStringFormat())
            {
                format.Alignment = GdiStringAlignment.Center;
                format.LineAlignment = GdiStringAlignment.Center;

                graphics.DrawString(text, GdiSystemFonts.MessageBoxFont, brush, clientRectangle, format);
            }
        }
Beispiel #34
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThumbnailPage"/> class.
        /// </summary>
        /// <param name="creator">The <see cref="ThumbnailCreator"/>
        /// (only used to get a jpeg compression encoder).</param>
        /// <param name="tgrid">The <see cref="ThumbnailGrid"/> that specifies
        /// the page layout.</param>
        /// <param name="displayFilename">The display name of the <see cref="AVFileSet"/>
        /// from which the thumbnails are generated.</param>
        /// <param name="filename">The fullpath of thumbnail page to create.</param>
        /// <param name="nFiles">The number of files in set (>0 for multi-part videos).</param>
        /// <param name="time">The time of first thumbnail on page.</param>
        /// <param name="pageNum">The page number (0 for overview page).</param>
        /// <param name="duration">The duration of the <see cref="AVFileSet"/>.</param>
        /// <param name="nPages">The total number of thumbnail pages.</param>
        /// <param name="stats">The stats of the <see cref="AVFileSet"/> to display
        /// in header.</param>
        public ThumbnailPage(ThumbnailCreator creator, 
            ThumbnailGrid tgrid,
            string displayFilename, string filename, int nFiles, TimeSpan time,
            int pageNum, TimeSpan duration, int nPages, string stats)
        {
            this._creator = creator;
            this._tgrid = tgrid;
            this._filename = filename;

            _pageBitmap = new System.Drawing.Bitmap (tgrid.Layout.Width,
                                                    tgrid.Layout.Height);
            _graphics = System.Drawing.Graphics.FromImage (_pageBitmap);

            _graphics.PageUnit = System.Drawing.GraphicsUnit.Pixel;

            _graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
            //_graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
            _graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            //_graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            _graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;

            // can't use TextRenderingHint.ClearTypeGridFit with CompositingMode.SourceCopy
            //_graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            //_graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            _graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

            // Affects image resizing
            _graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            // Affects anti-aliasing of filled edges
            //_graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            _graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;

            _font = new System.Drawing.Font ("Arial", (float) (7 * creator.TNSettings.ScaleFactor),
                                             System.Drawing.FontStyle.Bold);
            _brushWhite = new System.Drawing.SolidBrush (System.Drawing.Color.White);
            _brushBlack = new System.Drawing.SolidBrush (System.Drawing.Color.Black);
            _borderPen = new System.Drawing.Pen (System.Drawing.Color.Wheat,
                                                 tgrid.Layout.Border <= 1 ? 0 : tgrid.Layout.Border);
            _borderHilightPen = new System.Drawing.Pen (System.Drawing.Color.Red,
                                                 tgrid.Layout.Border <= 1 ? 0 : tgrid.Layout.Border);
            //_borderPen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
            //_borderPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Miter;

            _graphics.FillRectangle (_brushBlack, 0, 0,
                                    tgrid.Layout.Width,
                                    tgrid.Layout.Height);

            _thumbFormat = new System.Drawing.StringFormat ();
            switch (creator.TNSettings.LabelPosition)
                {
                case ThumbnailSettings.LabelPositions.None:
                case ThumbnailSettings.LabelPositions.LowerRight:
                    {
                    _thumbFormat.LineAlignment = System.Drawing.StringAlignment.Far;
                    _thumbFormat.Alignment = System.Drawing.StringAlignment.Far;
                    break;
                    }
                case ThumbnailSettings.LabelPositions.LowerLeft:
                    {
                    _thumbFormat.LineAlignment = System.Drawing.StringAlignment.Far;
                    _thumbFormat.Alignment = System.Drawing.StringAlignment.Near;
                    break;
                    }
                case ThumbnailSettings.LabelPositions.UpperRight:
                    {
                    _thumbFormat.LineAlignment = System.Drawing.StringAlignment.Near;
                    _thumbFormat.Alignment = System.Drawing.StringAlignment.Far;
                    break;
                    }
                case ThumbnailSettings.LabelPositions.UpperLeft:
                    {
                    _thumbFormat.LineAlignment = System.Drawing.StringAlignment.Near;
                    _thumbFormat.Alignment = System.Drawing.StringAlignment.Near;
                    break;
                    }
                }

            _headerFormat = new System.Drawing.StringFormat ();
            _headerFormat.LineAlignment = System.Drawing.StringAlignment.Center;
            _headerFormat.Alignment = System.Drawing.StringAlignment.Near;

            float inset = 2*tgrid.Layout.Margin;
            System.Drawing.RectangleF headerRectF =
                new System.Drawing.RectangleF (inset, 0,
                    this._tgrid.Layout.Width - 2*inset,
                    this._tgrid.Layout.HeaderHeight);
            //_graphics.DrawRectangle (_borderPen,
            //                         headerRectF.X,
            //                         headerRectF.Y,
            //                         headerRectF.Width,
            //                         headerRectF.Height);

            string leftSide;
            string timeformat = @"h\:mm\:ss";
            if (time.Milliseconds > 0 && creator.TNSettings.AlwaysShowMilliseconds)
                timeformat = @"h\:mm\:ss\.ffff";

            if (pageNum > 0)
                leftSide = String.Format ("{0} / {1} ({2} of {3})",
                                         time.ToString (timeformat),
                                         duration.ToString (@"h\:mm\:ss"),
                                         pageNum, nPages);
            else
                leftSide = String.Format ("{0}",
                                          duration.ToString (@"h\:mm\:ss"));
            if (nFiles > 0)
                leftSide += String.Format (" {0} files", nFiles);

            using (System.Drawing.Font headerFont = new System.Drawing.Font (
                ThumbnailPageLayout.FONT_NAME,
                (float) (ThumbnailPageLayout.FONT_SIZE * creator.TNSettings.ScaleFactor),
                System.Drawing.FontStyle.Bold))
                {
                _graphics.DrawString (leftSide,
                            headerFont, _brushWhite, headerRectF, _headerFormat);

                _headerFormat.Alignment = System.Drawing.StringAlignment.Far;
                _graphics.DrawString (stats,
                                      headerFont, _brushWhite, headerRectF, _headerFormat);
                float left = headerRectF.Left +
                                _graphics.MeasureString(leftSide, headerFont).Width;
                float right = headerRectF.Right -
                                _graphics.MeasureString (stats, headerFont).Width;
                headerRectF = new System.Drawing.RectangleF (
                    left,
                    headerRectF.Top,
                    right - left,
                    headerRectF.Height);

                _headerFormat.Alignment = System.Drawing.StringAlignment.Center;
                _graphics.DrawString (displayFilename,
                                      headerFont, _brushWhite, headerRectF, _headerFormat);
                }

            _pageNum = pageNum;
            _currentCol = 0;
            _currentRow = 0;
        }