C# 图片加白色边

public string WhiteUp(string t1, int x1, int y1)
        {
            //获取图片宽高
            string t3 = "..\\UploadFile\\lj_fj\\" + t1;
            t3 = System.AppDomain.CurrentDomain.BaseDirectory.ToString() + @"UploadFile\lj_fj\" + t1;
            System.Drawing.Image Img = System.Drawing.Image.FromFile(t3);
            int Width = Img.Width;
            int Height = Img.Height;
            //获取图片水平和垂直的分辨率
            float dpiX = Img.HorizontalResolution;
            float dpiY = Img.VerticalResolution;
            //创建一个位图文件
            Bitmap BitmapResult = new Bitmap(Width + x1 * 2, Height + y1 * 2, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            //设置位图文件的水平和垂直分辨率  与Img一致
            BitmapResult.SetResolution(dpiX, dpiY);
            //在位图文件上填充一个矩形框
            Graphics Grp = Graphics.FromImage(BitmapResult);
            System.Drawing.Rectangle Rec = new System.Drawing.Rectangle(0, 0, Width, Height + y1);
            //定义一个白色的画刷
            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.Clear(System.Drawing.Color.White);
            Grp.DrawImage(Img, x1, y1, Rec, GraphicsUnit.Pixel);

            string filename = DateTime.Now.ToString("yyyyMMddHHmmss");
            //string t2 = System.AppDomain.CurrentDomain.BaseDirectory.ToString() + @"UploadFile\lj_fj\" + filename + ".bmp";
            string t2 = t3.Replace(".jpg", ".bmp");
            // Img.Save(t2);
            //BitmapResult.Save("c:\\1.bmp");
            BitmapResult.Save(@t2);
            t2 = "http://zzhtxs.cn/UploadFile/lj_fj/" + filename + ".bmp";
            //返回位图文件
            Grp.Dispose();
            GC.Collect();
            return t2;

        }

 

r2 = cmz1.WhiteUp(r2, 90, 30);

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值