zoukankan      html  css  js  c++  java
  • C#图像处理(2):给图片加白边

    C#图片处理给图片添加白边:

            /// <summary>
            /// 在图片上方加入白边
            /// </summary>
            /// <param name="Img">图片</param>
            /// <param name="Margin">白边的高度,单位是像素</param>
            /// <returns>Bitmap</returns>
            public Bitmap WhiteUp(Image Img, int Margin)
            {
                //获取图片宽高
                int Width = Img.Width;
                int Height = Img.Height;
                //获取图片水平和垂直的分辨率
                float dpiX = Img.HorizontalResolution;
                float dpiY = Img.VerticalResolution;
                //创建一个位图文件
                Bitmap BitmapResult = new Bitmap(Width, Height + Margin, PixelFormat.Format24bppRgb);
                //设置位图文件的水平和垂直分辨率  与Img一致
                BitmapResult.SetResolution(dpiX, dpiY);
                //在位图文件上填充一个矩形框
                Graphics Grp = Graphics.FromImage(BitmapResult);
                System.Drawing.Rectangle Rec = new System.Drawing.Rectangle(0, 0, Width, Height + Margin);
                //定义一个白色的画刷
                SolidBrush mySolidBrush = new SolidBrush(System.Drawing.Color.White);
                //Grp.Clear(Color.White);
                //将矩形框填充为白色
                Grp.FillRectangle(mySolidBrush, Rec);
                //Grp.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                //Grp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //Grp.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                //向矩形框内填充Img
                Grp.DrawImage(Img, 0, Margin, Rec, GraphicsUnit.Pixel);
                //返回位图文件
                Grp.Dispose();
                GC.Collect();
                return BitmapResult;
            }
  • 相关阅读:
    dedecms 标签的基本用法
    修改config.php配置
    截取字符
    preg_replace 方法
    php过滤HTML标签、属性等正则表达式汇总
    各种正则验证
    解决问题 “You don't have permission to access /index.html on this server.”
    zend frameword 基本语法
    创建zend framework 项目要注意的
    PHP中级篇 Apache配置httpd-vhosts虚拟主机总结及注意事项[OK]
  • 原文地址:https://www.cnblogs.com/wupeihong/p/3919591.html
Copyright © 2011-2022 走看看