Advertisement
elviscortijo

Obtener tamaño de una imagen desde VBA

Nov 2nd, 2020 (edited)
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.82 KB | None | 0 0
  1. Function GetImageSize(ImagePath As String) As Variant
  2.     Dim imgSize(1)  As Integer
  3.     Dim wia         As Object
  4.    
  5.     On Error Resume Next
  6.     Set wia = CreateObject("WIA.ImageFile")
  7.     If wia Is Nothing Then Exit Function
  8.     On Error GoTo 0
  9.     wia.LoadFile ImagePath
  10.    
  11.     imgSize(0) = wia.Width
  12.     imgSize(1) = wia.Height
  13.    
  14.     Set wia = Nothing
  15.    
  16.     GetImageSize = imgSize
  17.  
  18. End Function
  19.  
  20.  
  21. Sub Probar()
  22.    
  23.     Dim sampleImagePath As String
  24.    
  25.     sampleImagePath = "C:\Users\Elvis Cortijo\Documents\Cedula_Elvis.jpg"
  26.    
  27.     MsgBox "El tamaño de la imagen es:" & vbNewLine & _
  28.            "Width: " & GetImageSize(sampleImagePath)(0) & " pixels" & vbNewLine & _
  29.            "Height: " & GetImageSize(sampleImagePath)(1) & " pixels", vbInformation, "Medidas de Imagen"
  30.    
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement