我如何能JPEG图像转换成PNG一个用透明的背景是什么? [英] How can I convert a JPEG image to a PNG one with transparent background?

查看:801
本文介绍了我如何能JPEG图像转换成PNG一个用透明的背景是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JPEG格式的图像,搭配白色背景和黑色圆圈。

I have a JPEG format image, with a white background and a black circle.

我怎么可以这样图像变换为PNG格式的白色背景将是透明和黑色依然存在?

How can I transform this image to a PNG format that the white background will be transparent and the black remains there?

我是一个程序员过了,如果在C#代码中的一些想法,我会很高兴。我也正在寻找一个转换器,工具,程序什么。

I'm a programmer too, and if there are some ideas in C# code I will be very happy. Also I'm looking for a converter, tool, program anything.

感谢您。

杰夫

推荐答案

下面是工作,但速度缓慢的解决方案。您可以通过使用Bitmap.LockBits()加快速度。

Here is working, but slow solution. You can speed it up by using Bitmap.LockBits().

using (Image img = Image.FromFile(filename))
using (Bitmap bmp = new Bitmap(img))
{
    for (int x = 0; x < img.Width; x++)
    {
        for (int y = 0; y < img.Height; y++)
        {
            Color c = bmp.GetPixel(x, y);
            if (c.R == 255 && c.G == 255 && c.B == 255)
                bmp.SetPixel(x, y, Color.FromArgb(0));
        }
    }
    bmp.Save("out.png", ImageFormat.Png);
}

这篇关于我如何能JPEG图像转换成PNG一个用透明的背景是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆