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;
            }

  • 相关阅读:
    Javascript文件加载:LABjs和RequireJS
    【译】前端开发者的基本要求
    正则基础之——NFA引擎匹配原理
    JavaScript 设计模式 安全沙箱模式
    jsdoc_toolkit
    JS判断手机浏览器
    JavaScript:Object.prototype.toString方法的原理
    FullCalendar 官方文档翻译2
    浏览器缓存机制
    jQuery.extend 函数详解
  • 原文地址:https://www.cnblogs.com/jason_chen/p/5611348.html
Copyright © 2011-2022 走看看