VB.Net - 删除image.PropertyItems数据 [英] VB.Net - Removing image.PropertyItems data

查看:338
本文介绍了VB.Net - 删除image.PropertyItems数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何成功删除图片属性项?我已经尝试加载图像,然后使用image.ProperyIdList循环,然后调用.RemovePropertyItem,然后将图像保存到新文件,但新文件仍然具有所有元数据。我还尝试将每个propertyItem.value的所有字节清零,但是当我保存时会导致genric gdi +错误。我也尝试将图像推入记忆流并返回,认为它会清除元数据。有什么想法吗?

How do I successfully remove an images property items? I have tried loading the image and then looping thru using the image.ProperyIdList and then calling .RemovePropertyItem and then saving the image to a new file, but the new file still has all the metadata. I have also tried to zero out all the bytes for each propertyItem.value but that causes a genric gdi+ error when I save. I have also tried pushing the image into a memeory stream and back, thinking it would clear the metadata. Any ideas?

推荐答案

我可以使用下面的代码完成以下任务。它不是最快但它确实有效。我基本上剥离了我想要的元数据,然后为没有属性的网络创建了一个新图像,从而确保个人数据不在照片中。

I was able to accomplish the following by using the code below. It is not the fastest but it does work. I basically strip off the metadata I want and then create a new image for the web with no properties, thus making sure the personal data is off the photo.

Using img As Image = Image.FromFile(fileName)
            Using newImage As New Bitmap(img.Width, img.Height)

                Using gr As Graphics = Graphics.FromImage(newImage)
                    gr.InterpolationMode = Drawing2D.InterpolationMode.Bilinear
                    gr.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height))
                End Using
                newImage.Save(newFileName)
            End Using
        End Using

这篇关于VB.Net - 删除image.PropertyItems数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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