zoukankan      html  css  js  c++  java
  • 设置图片边缘半透明

            直接上源码

            注:碰到的问题是画刷会以整个图形的最左侧为基础,不是以Rectangle为基础的

            /// <summary>
            /// 设置图片边缘透明
            /// </summary>
            /// <param name="oriBitmap">图片</param>       
            /// <returns></returns>
            public Bitmap SetBitmapLeftEdgeTransparent(Bitmap oriBitmap, Color backColor)
            {
                //渐变范围
                int gradientRange = oriBitmap.Width / 5;
                //建立图像对象
                Bitmap newBitmap = new Bitmap(oriBitmap.Width, oriBitmap.Height);
                Graphics graphics = Graphics.FromImage(newBitmap);           
                graphics.DrawImage(oriBitmap, new Rectangle(0, 0, oriBitmap.Width, oriBitmap.Height));

                //将后边部分200范围内 设置透明渐变
                Bitmap gradientBitmap = new Bitmap(gradientRange, newBitmap.Height);
                Graphics gradientGraphics = Graphics.FromImage(gradientBitmap);
                gradientGraphics.DrawImage(oriBitmap, 0, 0, new RectangleF(newBitmap.Width - gradientRange, 0, gradientRange, newBitmap.Height), GraphicsUnit.Pixel);
                Rectangle rect = new Rectangle(0, 0, gradientRange, newBitmap.Height);
                LinearGradientBrush lineBrush = new LinearGradientBrush(rect, Color.FromArgb(0, backColor.R, backColor.G, backColor.B), backColor, (float)0);           
                gradientGraphics.FillRectangle(lineBrush, rect);
                gradientGraphics.Dispose();
                //将渐变内容放置回来
                graphics.DrawImage(gradientBitmap, newBitmap.Width - gradientRange, 0);           
                graphics.Dispose();           
                return newBitmap;
            }

  • 相关阅读:
    【学习笔记】《架构整洁之道》(2)
    【学习笔记】《架构整洁之道》(1)
    《漫长的婚约》
    My 2020 work schedule
    canal-clientadapter 数据同步实验
    confluence异常关闭恢复
    nginx 添加第三方nginx_upstream_check_module 模块实现健康状态检测
    keepalived问题阐述及配置
    keepalived+lvs 部署
    lvs基础
  • 原文地址:https://www.cnblogs.com/jason_chen/p/5611348.html
Copyright © 2011-2022 走看看