Microsoft Developer Network >
Forums Home
>
Visual Studio Express Editions Forums
>
Visual Basic Express Edition
>
What worked in XP dont work in Windows 7
What worked in XP dont work in Windows 7
- I have a program which basically copies image files from a memory card to the computer.
Part of this program removes the EXIF orientation property.
This was all working fine in XP and Vista, but not in Win7
Here is a test program to show the problem i am having
Imports System.Drawing.Imaging Public Class Form1 Private Const EXIF_Orientation As Integer = 274 Private FileToTest As String = "D:\Skydive_0005.jpg" Private TmpFile As String = "D:\Test.jpg" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Create an Image object. Dim InputImage As Image = New Bitmap(FileToTest) 'Show original orientation MsgBox("Original: " & GetOrientation(InputImage)) 'Does orientation EXIF flag exist, if so remove it If Array.IndexOf(InputImage.PropertyIdList, EXIF_Orientation) > -1 Then InputImage.RemovePropertyItem(EXIF_Orientation) 'Show new orientation MsgBox("New: " & GetOrientation(InputImage)) 'Save image to tmp location InputImage.Save(TmpFile) 'Dispose image InputImage.Dispose() 'Read tmp image and check orientation Dim InputImage1 As Image = New Bitmap(TmpFile) 'Show orientation MsgBox("Confirmation: " & GetOrientation(InputImage1)) 'Dispose image InputImage1.Dispose() End Sub Private Function GetOrientation(ByVal PassedImage As Image) As Integer If Array.IndexOf(PassedImage.PropertyIdList, EXIF_Orientation) > -1 Then Dim OrientationProperty As PropertyItem = PassedImage.GetPropertyItem(EXIF_Orientation) Return System.BitConverter.ToInt16(OrientationProperty.Value, 0) Else Return -1 End If End Function End Class
In the test what should happen is
1) the source image is opened
2) the exising orientation is displayed
3) the orientation property is then removed
4) the new orientation is displayed (which should not exist)
5) the image is saved to a temp file
6) then the temp file is opened and the orientation is displayed (which should not exist)
On a Win7 system the origianl orientation is displayed, it is then removed, but it reappears in the temp file.
Does anyone know WTF is going on?
Answers
- I thing i may have found a solution, instead if just removing the property i dont want i set it to another value.
I made the following modifications and it seems to work.
replacedwith'Does orientation EXIF flag exist, if so remove it If Array.IndexOf(InputImage.PropertyIdList, EXIF_Orientation) > -1 Then InputImage.RemovePropertyItem(EXIF_Orientation)
'Does orientation EXIF flag exist, if so remove it If Array.IndexOf(InputImage.PropertyIdList, EXIF_Orientation) > -1 Then Dim NewValue As Byte() = {1} Dim Orientation As PropertyItem = InputImage.GetPropertyItem(EXIF_Orientation) Orientation.Value = NewValue InputImage.SetPropertyItem(Orientation) End If
- Marked As Answer byLloyd Quenby Saturday, November 07, 2009 9:24 PM
All Replies
- Hoi,
could it depends on rights ?
Dont know so much about W7 but maby this is other as in XP or VISTA.
And please: supress things like WTF :-(
Doei
Franz
Be a good forum member - mark posts that contain the answers to your questions or those that are helpful - I dont think it depends on rights as i have tried it with image files from a fat32 flash drive.
Anyone have any idea? - Other than your code showing some slight age (If Array.IndexOf(PassedImage.PropertyIdList, EXIF_Orientation) > -1 (you pass -1 several times and use msgbox)), so far, it looks good. I have some questions.
4) the new orientation is displayed (which should not exist)
6) then the temp file is opened and the orientation is displayed (which should not exist)
Those two are confusing.
I can tell you this. The problem is not in Windows 7.
Renee - The code is purely test code to show my problem, so it's not exactly streamlined, but it hopefully gets the point across.
The orientation is displayed before the property has been removed just to show that something is there, and i check to see if the property is there after it should have been removed just to make sure it has.
After i have removed the property, as i would expect the property is no longer there so my function returns -1
However after i save the modified file back to disk, i then reopen it as a check and find that the property is back again.
Hope this makes sense.
What could be the problem if it's not a specific windows 7 thing? - Yeah, it's very strange, i tested your code , it works like what you said.
Hope somebody knows this.
And this is windows 7 forumYou can try it
- Proposed As Answer byMaDFroG20091013 Wednesday, November 04, 2009 8:40 AM
- I thing i may have found a solution, instead if just removing the property i dont want i set it to another value.
I made the following modifications and it seems to work.
replacedwith'Does orientation EXIF flag exist, if so remove it If Array.IndexOf(InputImage.PropertyIdList, EXIF_Orientation) > -1 Then InputImage.RemovePropertyItem(EXIF_Orientation)
'Does orientation EXIF flag exist, if so remove it If Array.IndexOf(InputImage.PropertyIdList, EXIF_Orientation) > -1 Then Dim NewValue As Byte() = {1} Dim Orientation As PropertyItem = InputImage.GetPropertyItem(EXIF_Orientation) Orientation.Value = NewValue InputImage.SetPropertyItem(Orientation) End If
- Marked As Answer byLloyd Quenby Saturday, November 07, 2009 9:24 PM

