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 Answer
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
-
Hmm, just did this, but noted the file size increased by about 14k, just for those who come after... (30.694 bytes up to 45,191 bytes after saving) Sep 6, 2012 at 22:41