VB.Net - Removing image.PropertyItems data

旧城冷巷雨未停 提交于 2019-12-08 10:44:22

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/12117008/vb-net-removing-image-propertyitems-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!