释放资源-TagLib文件的artwork标签
在我的 C# 应用程序中,我正在为 mp3 文件创建标签。为此,我使用 TagLib 库/扩展。
标签之一是艺术品。我可以使用以下方法成功将艺术品添加到 mp3 的标签中:
TagLib.File f = TagLib.File.Create(path);
IPicture[] pictures = new IPicture[1];
pictures[0] = new Picture(artwork);
f.Tag.Pictures = pictures;
path
是 mp3 的完整路径,artwork
是艺术品的完整路径。
分配给“图片”标签后,我使用:
f.Save();
f.Dispose();
现在,将图稿文件移动到计算机上的另一个位置也符合我的兴趣。
为此,我使用:
File.Move(pathArtOrig, pathArtNew);
pathArtOrig
是图稿文件的当前完整路径,pathArtNew
是将其移动到的位置的完整路径。
问题是我收到以下错误:
IOException 未处理。该进程无法访问该文件,因为 它正在被另一个进程使用。
我根本不知道“释放”所使用的图稿文件的资源(它可能是 .jpg 文件)。正如您所看到的,我尝试使用上面的 Dispose(),但这并没有解决问题。
任何帮助表示赞赏。
In my C# application I'm creating tags for mp3 files. For this I use the TagLib library/extension.
One of the tags is the artwork. I can successfully add the artwork to the mp3's tag by using:
TagLib.File f = TagLib.File.Create(path);
IPicture[] pictures = new IPicture[1];
pictures[0] = new Picture(artwork);
f.Tag.Pictures = pictures;
path
is the full path to the mp3, artwork
is the full path to the artwork.
After assigning to the Pictures tag, I use:
f.Save();
f.Dispose();
Now, it is also in my interest to move the artwork file to another location on the computer.
For this I use:
File.Move(pathArtOrig, pathArtNew);
pathArtOrig
is the current full path of the artwork file, and pathArtNew
is the full path of where it's going to be moved to.
The problem is the fact that I get the following error:
IOException was unhandled. The process cannot access the file because
it is being used by another process.
I have simply no idea to "release" the resource of the artwork file used (it could be a .jpg file). As you can see, I tried with Dispose() above, but that's not doing the trick.
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,看来我自己才发现错误。
在我的代码中,在创建标签之前,我将文件加载到图片框中。它存储在位图中。
现在我在创建标签之前 Dispose() 这个位图,一切都很好。现在可以移动文件。
Sorry, it seems I just found the error myself.
One place in my code, before tag creation, I was loading the file into a picturebox. It is stored in a Bitmap.
Now I Dispose() this Bitmap before the tag creation, and all is fine. File can now be moved.