VB.Net - Removing image.PropertyItems data

2019-06-12 13:54发布

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条回答
唯我独甜
2楼-- · 2019-06-12 14:33

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
查看更多
登录 后发表回答