从图像清除元数据的简便方法? [英] Easy way to clean metadata from an image?

查看:131
本文介绍了从图像清除元数据的简便方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个处理图像处理的公司项目提供服务,其中一种方法应该从传递给它的图像中清除元数据.

I'm working on a service for a company project that handles image processing, and one of the methods is supposed to clean the metadata from an image passed to it.

认为实现目前可以使用,但是我不确定它是否影响图像质量或是否有更好的方法来处理此任务.你能告诉我是否有更好的方法吗?

I think implementation I currently have works, but I'm not sure if it's affecting the quality of images or if there's a better way to handle this task. Could you let me know if you know of a better way to do this?

这是有问题的方法:

public byte[] CleanMetadata(byte[] data)
{
    Image image;

    if (tryGetImageFromBytes(data, out image))
    {
        Bitmap bitmap = new Bitmap(image);

        using (var graphics = Graphics.FromImage(bitmap))
        {
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.CompositingMode = CompositingMode.SourceCopy;
            graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            graphics.DrawImage(image, new Point(0, 0));
        }

        ImageConverter converter = new ImageConverter();

        return (byte[])converter.ConvertTo(image, typeof(byte[]));
    }

    return null;
}

tryGetImageFromBytes方法供参考:

private bool tryGetImageFromBytes(byte[] data, out Image image)
{
    try
    {
        using (var ms = new MemoryStream(data))
        {
            image = Image.FromStream(ms);
        }
    }
    catch (ArgumentException)
    {
        image = null;

        return false;
    }

    return true;
}

重申:是否有更好的方法从图像中删除不涉及重绘的元数据?

To reiterate: is there a better way to remove metadata from an image that doesn't involve redrawing it?

谢谢.

推荐答案

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