图片转成透明底

时间:2020-06-23 10:10:59   收藏:0   阅读:215
string sp = Server.MapPath("/");//"/PDF/tz/tempword/"
            if (!System.IO.Directory.Exists(sp))
            {
                System.IO.Directory.CreateDirectory(sp);
            }
            //Request.Files[0].SaveAs(path);

            ImageAttributes vAttr = new ImageAttributes(); //vAttr是关键

            //图像中与0,0那点相同的颜色要变成透明

            Bitmap bitmap = new Bitmap(Request.Files[0].InputStream);
            Bitmap bitmappng = new Bitmap(165, 165);//新生成的图片宽与高
            vAttr.SetColorKey(bitmap.GetPixel(0, 0), bitmap.GetPixel(0, 0));
            Graphics g = Graphics.FromImage(bitmappng);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.DrawImage(bitmap, new Rectangle(10, 10, 165, 165), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, vAttr);
            g.Save();
            g.Dispose();
            bitmappng.Save(sp + "png.png", ImageFormat.Png);

 

原文:https://www.cnblogs.com/gxivwshjj/p/13180267.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!