Cómo obtener el ancho, alto y tamaño en KBytes de una imagen

Para obtener el ancho, el alto, y el tamaño en KBytes de una imagen, utiliza el siguiente código:

VB.NET:
  1. Dim Im As New System.Drawing.Bitmap("c:\Imagen.jpg")
  2. Dim FIm As New FileInfo("c:\Imagen.jpg")
  3. Dim TamanoBytes, TamanoKBytes As Long
  4. TamanoKBytes = FIm.Length / 1024
  5. TamanoBytes = FIm.Length 'Por si lo quieres en Bytes
  6. 'InfoImagen es un Label
  7. InfoImagen.Text = "Ancho: " & Im.Width & " pixeles; Alto: " & Im.Height & " pixeles; Tamaño: " & TamanoKBytes & " KB;"
  8. 'Siempre recuerda cerrar el Bitmap
  9. Im.Dispose()

Si no cierras el Bitmap utilizando su método Dispose, aparecerá un error que dice que la imagen está siendo utilizada por otro proceso cuando la quieras borrar o modificar su nombre.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.