Closed JefEe closed 2 years ago
Can you provide more details on the project? Framework version will be helpful. If you provide a reproduction project it'll be really easy to look and see what's wrong
Your code looks correct but I have not used this on VB only C#
Hi,
I uploaded to WE-transfer a copy of the program (visual studio) https://we.tl/t-F72pFSTdJG
Is this sufficient as "reproduction project"?
Please upload the project directly to this GitHub thread. You can drag and drop into a comment
Secondly, this is a batch program for mass converting. When processing a large set 500+ images i get this error. I believe it's same reason why the files are still in use.
ex.Message = "Heif image exception - Input file does not exist: Unspecified: Error opening file: Too many open files (24)" & vbLf
I think I see the problem, didn't notice it until I pulled the code. In the snippet above you grab the PrimaryImage
and never dispose of it. Looking at the README getting started docs (copied below)
using (var image = new HeifImage("image.heic"))
using (var primary = image.Primary())
{
primary.Write("output.jpeg", 90);
}
Your code needs to store the PrimaryImage
. Using your provided code I was able to convert 10 heic images in a folder to jpeg. Here is the updated HeifImage
code
Dim oHEICimage As New HeifImage(FullPath)
Dim oNewPath As String = System.IO.Path.Combine(Directory, Name & ".jpeg")
Dim oPrimary as IImage = oHEICimage.PrimaryImage()
oPrimary.Write(oNewPath)
oPrimary.Dispose()
oHEICimage.Dispose()
Return oNewPath
Hope this helps - closing issue out as there is no bug with the library.
Can you check again? I altered the code as recomended, but thet error persists.
Dim oNewPath As String = System.IO.Path.Combine(Directory, Name & ".jpeg")
Dim oHEICimage As New HeifImage(FullPath)
Dim oPrimary As IImage = oHEICimage.PrimaryImage
oHEICimage.PrimaryImage.Write(oNewPath)
oPrimary.Dispose()
oHEICimage.Dispose()
System.IO.File.Delete(FullPath)
Deletion is not possible due to base file in use.
I just tried the code you provided in the sample project and I am unable to reproduce your issue. What version of .NET are you using? Is it framework of the modern .NET? Something may be getting cached, maybe try cleaning the solution and manually deleting your bin/obj folders
Target framework is .NET 6.0 When I clean bin/obj folders the error persists
🤔🤔
I am running your project with the same code and it works for me and not you. We are both running .NET 6.0 and yours throws an exception and mine doesn't. I am not really sure what else to say, if I can't reproduce the problem you are seeing then it is difficult for me to provide anymore advice, sorry 😢
Hi,
When I save an HEIC image as JPEG i cannot delete the file during the runtime. The file stays in use by another process.
Any suggestions how to remove the image after making the conversion (to avoid duplicates)