改变图片alpha通道值

To remove the alpha channel from single image use this command:

convert input.png -alpha off output.png
To remove the alpha channel from all images inside a folder, make use find to first find all PNG files, and then run ‘m through convert:

find . -name “*.png” -exec convert “{}” -alpha off “{}” \;
Please test on a COPY of your files to be sure.

see dialog below, and the answer is based on that “we need to remove alpha that is not 255”

convert input.png -channel A -threshold 254 output.png
and for batch

mkdir batch
FOR %G IN (*.png) DO convert %G -channel A -threshold 254 batch\%G

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
改变图片透明度 很好的学习用工码 attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); Bitmap resultImage = new Bitmap(srcImage.Width, srcImage.Height); Graphics g = Graphics.FromImage(resultImage); g.DrawImage(srcImage, new Rectangle(0, 0, srcImage.Width, srcImage.Height), 0, 0, srcImage.Width, srcImage.Height, GraphicsUnit.Pixel, attributes); return resultImage; } #region 不安全代码 需要设置项目允许不安全代码 /// /// 方法二 设置图像透明度,若原图不为32位ARGB格式,则自动转换为32位ARGB输出 /// /// 原图 /// 透明度(0~1之间双精度浮点数) //public static unsafe void SetTransparent(ref Bitmap src, double transparency) //{ // if (transparency 1.0) // throw new ArgumentOutOfRangeException("透明度必须为0~1之间的双精度浮点数"); // BitmapData srcData; // Rectangle rect; // byte* p; // rect = new Rectangle(0, 0, src.Width, src.Height); // src = src.Clone(rect, PixelFormat.Format32bppArgb); // //转换到32位,否则丢失透明度 // srcData = src.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); // //锁定字节数组到内存 // p = (byte*)srcData.Scan0.ToPointer(); // //获取字节数组在内存中地址 // if (src.PixelFormat == PixelFormat.Format32bppArgb) // { // //如果是32位图片,有Alpha通道,以原Alpha通道为基准 // p += 3; // //默认修改Alpha通道 // for (int i = 0; i < srcData.Stride * srcData.Height; i += 4) // { // *p = (byte)(*p * transparency); // //原Alpha通道*透明度 // p += 4; // }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值