Hi i'm making a small app' that will load some .mp3 songs and resize their covers to required size in bytes.
I think the best will be to changing real resolution until it won't be less than required. But i really don't know how to it or how to save the ID3 pic'.
Songs are loaded from OpenFileDialog and required size is loaded from simple textBox.
I'm working with taglib# and C#(WPF), but if there is better library for this problem, i will not resist.
Here's my example, which truly resize the pic', but it shortened it.
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
int size;
try
{
size = int.Parse(textBox1.Text);
}
catch (FormatException)
{
MessageBox.Show("Enter requiered size!", "Err");
return;
}
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt = ".mp3";
dlg.Filter = "mp3 files (.mp3) | *.mp3";
dlg.Multiselect = true;
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
foreach (string file in dlg.FileNames)
{
var song = TagLib.File.Create(file);
if (song.Tag.Pictures.Length > 0)
{
// var bin = (byte[])(song.Tag.Pictures[0].Data.Data);
song.Tag.Pictures[0].Data.Resize(size);
}
}
}
}