• 设置图片边缘半透明


            直接上源码

            注:碰到的问题是画刷会以整个图形的最左侧为基础,不是以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;
            }

  • 相关阅读:
    Luogu 4841 城市规划
    Luogu 4721 【模板】分治 FFT
    Luogu 4091 [HEOI2016/TJOI2016]求和
    Luogu 3723 [AH2017/HNOI2017]礼物
    FFT笔记
    Luogu 4900 食堂
    Luogu 4155 [SCOI2015]国旗计划
    Luogu 4069 [SDOI2016]游戏
    Luogu 4254 [JSOI2008]Blue Mary开公司
    Luogu 4251 [SCOI2015]小凸玩矩阵
  • 原文地址:https://www.cnblogs.com/jason_chen/p/5611348.html
Copyright © 2020-2023  润新知