1

Below is the sample code that is giving error with the microsoft sample pictures (tulips.jpg) image

bufferedImage = Imaging.getBufferedImage(new file("Tulips.jpg"));

File imageFile = new File("outputfile.jpg");
final Map<String, Object> optionalParams = new HashMap<String, Object>();
Imaging.writeImage(bufferedImage, imageFile, ImageFormats.JPEG, optionalParams);

This code is giving "This image format (Jpeg-Custom) cannot be written." Any pointers would be of great help. I have searched stackoverflow, google - no help so far.

When I read the documentation it states that if the bufferedImage.getType()== TYPE_UNKNOWN, it gives this message but dont have a clue why it is giving UNKNOWN.

Thanks so much for your help.

user9383
  • 11
  • 1
  • 2

1 Answers1

4

Write to JPEG files is not supported by Apache Commons Imaging. You can see supported format information here: http://commons.apache.org/proper/commons-imaging/formatsupport.html (even JPEG read is not fully supported). However write to some other formats supported (e.g. you can change image format to PNG in your writeImage function call and it will work).

Moreover Apache Commons Imaging is not released yet, so I wouldn't recommend using it in a critical code.

As alternative you can take a look into JDK javax.imageio.ImageIO class (some examples: https://docs.oracle.com/javase/tutorial/2d/images/saveimage.html).

What exactly are you trying to achieve in your code?

Igor Uzhviev
  • 308
  • 1
  • 4
  • Thankis for the answer. I overlooked the write column. I am trying to read CMYK images and convert to RGB. Also read DPI if less than 300, resave and set to 300 dpi. I have gone through forums and it all lead to apache commons imaging [link](http://stackoverflow.com/questions/20096810/determine-dpi-of-image-in-java) [link] (http://stackoverflow.com/questions/3123574/how-to-convert-from-cmyk-to-rgb-in-java-correctly). – user9383 Mar 13 '17 at 10:51
  • @luckyfitness My [TwelveMonkeys ImageIO](https://github.com/haraldk/TwelveMonkeys) plugins will allow `ImageIO` to read CMYK JPEGs and write them back in RGB format. The DPI can be controlled through standard metadata (`IIOMetadata` class). – Harald K Mar 13 '17 at 16:13
  • haraldK - Thanks. I checked twelveMonkeys ImageIO but the latest version says to use JDK.1.8, we are using JDK1.6.x. so not sure if it there are any fixes that have fixed after 3.0.x version. Also does it tell the dpi to see if it needs to be resaved at 300. – user9383 Mar 13 '17 at 17:17
  • @luckyfitness The current version (3.3.x) requires Java 7. If you need to run on Java 6, that's unfortunate. There's a fork somewhere that has backported a recent version to run on Java 5 or 6, but I'm not the maintainer of that fork. Yes, as I said, DPI can be inspected and modified through the standard `IIOMetadata` class. PS: Add a @ before the name to notify a user about your message. :-) – Harald K Mar 14 '17 at 09:11
  • It's interesting because the sanselan incubation library before commons-imaging supported jpeg conversion. So it seems like commons-imaging isn't a complete drop-in replacement for the former. It is in still in alpha so maybe I was expecting to much – Alkanshel Aug 16 '22 at 20:48