Jody wrote: > > Slowly I get the impression the best thing (from a UI developer > perspective) is > > - a) hard coding the DIFFERENT supported file formats for the UI and > just check if at least one writer can support them and is able to write the > image (spi.canEncodeImage()) and > > - b) let ImageIO decide which writer to take for each format (similar to > what you had done, except you used the file extension). > > > I looked at the code ImageIO does not decide; it just chooses the first > one near as I can tell. The FactorySPI system can sort them into some > kind of order - but the IIRegistry thing would get that order as well.
Correct. Today I created a Swing file chooser for images - and I tried a new approach quite successfully: - I iterate the list of writer SPIs and filter those capable for writing my image - I fetch all their file extensions (not image formats) - I create SimpleFileFilter instances (a class from my own library) from them - Using a hard coded map of duplicates I can turn jpg/jpeg and tif/tiff into ONE file filter each. - File filters already in the list are not added again. - After the user has chosen one filter in the file chooser dialog I can fetch the first file extension of this filter - I iterate the list of writer SPIs again - The first writer SPI supporting the selected extension and capable of writing my image is used. Since the SPIs are returned in a best first order this is perfectly fine. - I set the output stream and let the writer write the image. This works very well. The only downside is that I don't have any useful descriptions for the file filters. They read "(*.jpg;*.jpeg)" or some such. But this is cosmetical. At least I have two things solved: - No duplicate entries - Best suitable writer is used. Next step for me is to utilize the image parameters (they can seemingly be automatically discovered) to let the user set compression type and compression quality in the file save dialog for formats supporting this. -- Matthias Basler [EMAIL PROTECTED] _______________________________________________ User-friendly Desktop Internet GIS (uDig) http://udig.refractions.net http://lists.refractions.net/mailman/listinfo/udig-devel
