J
Joaquin Corchero
Hi, I have this code which it should change the EXIF file properties of
images, but there is something that doesn't work, any ideas???
Private Sub ShowBitMapProp(ByVal sFile As String)
Dim sExt = LCase(sFile).Substring(sFile.LastIndexOf("."))
If sExt = ".jpg" Or sExt = ".gif" Then
Response.Write("ShowBitMapProp<br>" & vbCrLf)
Dim oBitmap As Image = Image.FromFile(sFile)
'Dim oProba As Image = Image.FromFile(sFile)
'oProba.Dispose()
'oBitmap = oProba.Clone
'Dim oBitmap As Bitmap = New Bitmap(sFile)
'Dim ooBitmap As Birmap = oBitmap.FromFile(sFile)
Dim iConta As Integer
Response.Write("Number of properties: " &
oBitmap.PropertyItems.Length.ToString & "<br>" & vbCrLf)
Dim oPrps() As System.Drawing.Imaging.PropertyItem
Dim oPrp As System.Drawing.Imaging.PropertyItem
oPrps = oBitmap.PropertyItems
Dim bByte() As Byte
Dim bConv As System.BitConverter
Dim utf As New System.Text.UTF7Encoding
Dim bNewValue() As Byte
Dim iCont As Integer
Dim sProba As String = "Joaquin"
For iConta = 0 To oPrps.Length
oPrp = oPrps(iConta)
'Response.Write(oBitmap.PropertyIdList.GetValue(iConta).ToString & " Idlist
" & iConta & "<br>" & vbCrLf)
If oPrp.Id.ToString = "40091" Or oPrp.Id.ToString = "40092" Or _
oPrp.Id.ToString = "40093" Or oPrp.Id.ToString = "40094" Or _
oPrp.Id.ToString = "40095" Then
Response.Write(oPrp.Id & "<br>")
bByte = oPrp.Value
Try
Response.Write("Old Value: " & utf.GetString(bByte) & "; ")
bNewValue = utf.GetBytes(utf.GetString(bByte))
bNewValue = utf.GetBytes("Joaquin")
oPrp.Id = oPrp.Id
oPrp.Type = oPrp.Type
oPrp.Len = System.Text.ASCIIEncoding.Unicode.GetBytes(sProba).Length
oPrp.Value = System.Text.ASCIIEncoding.Unicode.GetBytes(sProba)
oBitmap.SetPropertyItem(oPrp)
Catch
Response.Write(Err.Description & " Error<br>")
End Try
End If
'40091: Title
'40092: Comments
'40093: Author
'40094: Keywords
'40095: Subject
Next
Try
'File.Delete(sFile)
oBitmap.Save(sFile)
Catch
Response.Write(Err.Description & " Error 2 <br>")
End Try
End If
End Sub
Thank you for your help
images, but there is something that doesn't work, any ideas???
Private Sub ShowBitMapProp(ByVal sFile As String)
Dim sExt = LCase(sFile).Substring(sFile.LastIndexOf("."))
If sExt = ".jpg" Or sExt = ".gif" Then
Response.Write("ShowBitMapProp<br>" & vbCrLf)
Dim oBitmap As Image = Image.FromFile(sFile)
'Dim oProba As Image = Image.FromFile(sFile)
'oProba.Dispose()
'oBitmap = oProba.Clone
'Dim oBitmap As Bitmap = New Bitmap(sFile)
'Dim ooBitmap As Birmap = oBitmap.FromFile(sFile)
Dim iConta As Integer
Response.Write("Number of properties: " &
oBitmap.PropertyItems.Length.ToString & "<br>" & vbCrLf)
Dim oPrps() As System.Drawing.Imaging.PropertyItem
Dim oPrp As System.Drawing.Imaging.PropertyItem
oPrps = oBitmap.PropertyItems
Dim bByte() As Byte
Dim bConv As System.BitConverter
Dim utf As New System.Text.UTF7Encoding
Dim bNewValue() As Byte
Dim iCont As Integer
Dim sProba As String = "Joaquin"
For iConta = 0 To oPrps.Length
oPrp = oPrps(iConta)
'Response.Write(oBitmap.PropertyIdList.GetValue(iConta).ToString & " Idlist
" & iConta & "<br>" & vbCrLf)
If oPrp.Id.ToString = "40091" Or oPrp.Id.ToString = "40092" Or _
oPrp.Id.ToString = "40093" Or oPrp.Id.ToString = "40094" Or _
oPrp.Id.ToString = "40095" Then
Response.Write(oPrp.Id & "<br>")
bByte = oPrp.Value
Try
Response.Write("Old Value: " & utf.GetString(bByte) & "; ")
bNewValue = utf.GetBytes(utf.GetString(bByte))
bNewValue = utf.GetBytes("Joaquin")
oPrp.Id = oPrp.Id
oPrp.Type = oPrp.Type
oPrp.Len = System.Text.ASCIIEncoding.Unicode.GetBytes(sProba).Length
oPrp.Value = System.Text.ASCIIEncoding.Unicode.GetBytes(sProba)
oBitmap.SetPropertyItem(oPrp)
Catch
Response.Write(Err.Description & " Error<br>")
End Try
End If
'40091: Title
'40092: Comments
'40093: Author
'40094: Keywords
'40095: Subject
Next
Try
'File.Delete(sFile)
oBitmap.Save(sFile)
Catch
Response.Write(Err.Description & " Error 2 <br>")
End Try
End If
End Sub
Thank you for your help