- Local time
- Today, 23:13
- Joined
- Sep 12, 2006
- Messages
- 15,909
I've spent hours on this , and it's close but no cigar.
I downloaded a database called wiarotate.accdb
I thought it was from here, but it's in German, and there's no information about the source. I've included it here for interest.
It uses the WIA library.
The utility reads the exif data from an image, determines the rotational status value, and applies that value, on a copy of the image processed in the WIA module, and then copies the data back into the image object.
I am trying to use the code in my own app, and I when I try to load the rotated image I get error 2192, "image is not a device independent format" is an example.
The wiarotate database is attached.
This code works in wiarotate.
In my own app, with some of the code changed very slightly the line labelled B: fails with error 2192, but using my code in WIARotate, it works correctly, so I can only think I must be missing something.
What I get is this
An image not requiring rotation generates a system error that no filter was used, and then resumes at label B, and then all images whether rotated or not produces the 2192 error. I assume the WIArotate code gets the system error, but ignores it, but it doesn't get the 2192 error.
I can only think there is something different about my app, and my image controls are different somehow to the image controls in the WIARotate database.
The error 2192 occurs with this line
Let Me.Image1.PictureData = Image.FileData.BinaryData 'display the adjusted image from the WIA process.
I have checked all the references, and adjusted them so they are identical in both databases.
CODE IN WIAROTATE
MYCODE
I downloaded a database called wiarotate.accdb
I thought it was from here, but it's in German, and there's no information about the source. I've included it here for interest.
It uses the WIA library.
The utility reads the exif data from an image, determines the rotational status value, and applies that value, on a copy of the image processed in the WIA module, and then copies the data back into the image object.
I am trying to use the code in my own app, and I when I try to load the rotated image I get error 2192, "image is not a device independent format" is an example.
The wiarotate database is attached.
This code works in wiarotate.
In my own app, with some of the code changed very slightly the line labelled B: fails with error 2192, but using my code in WIARotate, it works correctly, so I can only think I must be missing something.
What I get is this
An image not requiring rotation generates a system error that no filter was used, and then resumes at label B, and then all images whether rotated or not produces the 2192 error. I assume the WIArotate code gets the system error, but ignores it, but it doesn't get the 2192 error.
I can only think there is something different about my app, and my image controls are different somehow to the image controls in the WIARotate database.
The error 2192 occurs with this line
Let Me.Image1.PictureData = Image.FileData.BinaryData 'display the adjusted image from the WIA process.
I have checked all the references, and adjusted them so they are identical in both databases.
CODE IN WIAROTATE
Code:
Private Sub Liste0_Click()
Dim Image As WIA.ImageFile
Dim ip As WIA.ImageProcess
Let Me.Bild3.Picture = Me.path & Me.Liste0.ItemData(Me.Liste0.ListIndex)
Let Me.Bild4.Picture = ""
Let Me.TB_Orientation.Value = 1
Set Image = New WIA.ImageFile
Call Image.LoadFile(Me.path & Me.Liste0.ItemData(Me.Liste0.ListIndex))
If Image.Properties.Exists("274") Then
Set ip = New WIA.ImageProcess
With ip
On Error GoTo B
Let Me.TB_Orientation.Value = Image.Properties("274").Value
Select Case Image.Properties("274").Value
Case 2: Call mkFlt(ip, "FlipHorz")
Case 3: Call mkFlt(ip, "Rotate", 180)
Case 4: Call mkFlt(ip, "FlipVert")
Case 5: Call mkFlt(ip, "FlipHorzandRotate", 270)
Case 6: Call mkFlt(ip, "Rotate", 90)
Case 7: Call mkFlt(ip, "FlipHorzandRotate", 90)
Case 8: Call mkFlt(ip, "Rotate", 270)
End Select
Set Image = .Apply(Image)
End With
End If
B: Let Me.Bild4.PictureData = Image.FileData.BinaryData
X: Exit Sub
E: Debug.Print Err.Description
End Sub
Sub mkFlt(ip As WIA.ImageProcess, sflip$, Optional ByVal rotatevalue As Integer)
With ip
Select Case sflip
Case "FlipHorzandRotate"
Call mkFlt(ip, "FlipHorz")
Call mkFlt(ip, "Rotate", rotatevalue)
Case "FlipHorz"
Call .Filters.Add(.FilterInfos("RotateFlip").FilterID)
Let .Filters(.Filters.Count).Properties("FlipHorizontal") = True
Let .Filters(.Filters.Count).Properties("FlipVertical") = True
Call mkFlt(ip, "FlipVert")
Case "Rotate"
Call .Filters.Add(.FilterInfos("RotateFlip").FilterID)
Let .Filters(.Filters.Count).Properties("RotationAngle") = rotatevalue
Case "FlipVert"
Call .Filters.Add(.FilterInfos("RotateFlip").FilterID)
Let .Filters(.Filters.Count).Properties("FlipVertical") = True
End Select
End With
End Sub
MYCODE
Code:
Public Sub ProcessImage(infile As String)
Dim txtfile As String
Dim Image As WIA.ImageFile
Dim ip As WIA.ImageProcess
txtfile = infile
MsgBox "Processing: " & txtfile 'to check the file being processed
Let Me.ImageOrig.Picture = infile 'just to display the unadjusted image
Let Me.Image1.Picture = ""
Let Me.TB_Orientation.Value = 1
Set Image = New WIA.ImageFile
Call Image.LoadFile(infile)
If Image.Properties.Exists("274") Then
Set ip = New WIA.ImageProcess
With ip
' On Error GoTo B:
On Error GoTo Err_Handler1
Let Me.TB_Orientation.Value = Image.Properties("274").Value
Select Case Image.Properties("274").Value
Case 2: Call mkFlt(ip, "FlipHorz")
Case 3: Call mkFlt(ip, "Rotate", 180)
Case 4: Call mkFlt(ip, "FlipVert")
Case 5: Call mkFlt(ip, "FlipHorzandRotate", 270)
Case 6: Call mkFlt(ip, "Rotate", 90)
Case 7: Call mkFlt(ip, "FlipHorzandRotate", 90)
Case 8: Call mkFlt(ip, "Rotate", 270)
End Select
Set Image = .Apply(Image)
End With
End If
B: On Error GoTo Err_Handler2
Let Me.Image1.PictureData = Image.FileData.BinaryData 'display the adjusted image from the WIA process.
X: Exit Sub
E: 'you can't get here now. This is replaced by the 2 error handlers below.
Debug.Print Err.Description
MsgBox "Error: " & Err & " Desc: " & Err.Description
Exit Sub
Err_Handler1:
MsgBox "Error: " & Err & " Desc: " & Err.Description, , "Handler1"
Resume B:
Err_Handler2:
MsgBox "Error: " & Err & " Desc: " & Err.Description, , "Handler2"
End Sub