I'm trying to write a function that takes a file as an image (JPG, GIG, PNG, etc) and records the dimensions. If the file is not an image, or the dimensions cannot be determined (or otherwise 'bad'), the file is deleted.
One method I found for getting the image dimensions immediately is discussed on Example Depot
Let's say after making this call I want to delete the file for some reason. The call [new File.delete("image.gif")] fails [returns false and does not delete the file] because the above code locks the file.
First off, is there a way to release the lock the above code puts on my file so that it can be safely deleted? Second, I'd take any recommendations for non-Swing libraries that would replace the above code. I'm not fond of using Swing code in what is definitely a non-swing application (also why I didn't post to the Swing forum).
I was thinking of http://test.javaranch.com/ulf/ImageInfo.java (which doesn't seem to be available on the net any more on whichever site I found it originally), but both seem to cover a similar list of formats.
Scott Selikoff wrote:I'm trying to write a function that takes a file as an image (JPG, GIG, PNG, etc) and records the dimensions. If the file is not an image, or the dimensions cannot be determined (or otherwise 'bad'), the file is deleted.
<snip/>
Let's say after making this call I want to delete the file for some reason. The call [new File.delete("image.gif")] fails [returns false and does not delete the file] because the above code locks the file.
First off, is there a way to release the lock the above code puts on my file so that it can be safely deleted? Second, I'd take any recommendations for non-Swing libraries that would replace the above code. I'm not fond of using Swing code in what is definitely a non-swing application (also why I didn't post to the Swing forum).
The ImageIcon constructor that takes a String argument loads the image using Toolkit, and that may be where the file is getting locked (in the native method).
There's no need for any Swing code. Load the image using ImageIO#read(...) which blocks until the file is completely read.
luck, db
There are no new questions, but there may be new answers.
While I'm at it, anyone have a good method for reading duration/dimensions of an FLV movie? The only solution I've seen on the web is to read the first ~400 bytes and do a text search for the words "duration", "width", "height". It seems awfully buggy, but it actually works. Hoping there was something more elegant though.