Extract album from MP3 files using TagLib. Is there a better way to write this code?

I am using Visual Basic 9 (VS2008) and TagLib.

The following code extracts the album art from an MP3 file and displays it in a PictureBox.

Is there a better way to write this code?

 Dim file As TagLib.File = TagLib.File.Create(filepath)

 If file.Tag.Pictures.Length >= 1 Then
    Dim bin As Byte() = DirectCast(file.Tag.Pictures(0).Data.Data, Byte())
    PreviewPictureBox.Image = Image.FromStream(New MemoryStream(bin)).GetThumbnailImage(100, 100, Nothing, System.IntPtr.Zero)
 End If
+3
source share
2 answers

TagLib, , . , , , , . , "Infer". , .

 Option Infer On
 ...
 Dim file = TagLib.File.Create(filepath)

 If file.Tag.Pictures.Length >= 1 Then
    Dim bin = DirectCast(file.Tag.Pictures(0).Data.Data, Byte())
    PreviewPictureBox.Image = Image.FromStream(New MemoryStream(bin)).GetThumbnailImage(100, 100, Nothing, System.IntPtr.Zero)
 End If
+2

.

, , TagLib.File.Create() "Nothing". , Tag - , , ".Pictures".

+3

Source: https://habr.com/ru/post/1702183/


All Articles