I use TagLib to convert an album picture from mp3 to byte []:
TagLib.File tagFile = TagLib.File.Create(el); IPicture Pic = tagFile.Tag.Pictures[0]; byte[] Picture = Pic.Data.Data.ToArray(); I write in DB, then I take out and try to convert to BitmapImage and write to Control Image FindedSongPicture in the main window:
Converting function:
private BitmapImage Bitmap2BitmapImage(Bitmap bitmap) { BitmapImage bi = new BitmapImage(); using (MemoryStream ms = new MemoryStream()) { bitmap.Save(ms, ImageFormat.Png); ms.Position = 0; bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); return bi; } } The executable code where byte [] song.songPicture:
using (var ms = new System.IO.MemoryStream(song.songPicture)) { using (var img = Image.FromStream(ms)) { FindedSongPicture.Source = Bitmap2BitmapImage(img as Bitmap); } } As a result, nothing is displayed in the Image.
The first piece takes the picture of the album from the mp3 file and pulls it out byte [], TagLib allows
The second piece is the conversion function from Bitmap to BitmapImage, since in the control Image on the main form you can push only BitmapImage
The 3rd piece converts byte [] to a Bitmap, calls the Bitmap-> BitmapImage function and shoves BitmapImage into the Image control in the main window, FindedSongPicture is the name of the Image control in the main window
song.songPicture this byte []
TagLib - a library for working with tags mp3 file
What is the problem?