java - Convert RGB PNG to CMYK JPEG (using ICC Color Profiles) -
i need convert png-file cmyk jpeg.
during research i've found multiple articles on decribing problem. i've copied this answer using bufferedimage
, colorconvertop
.
i came little example:
public static void main(final string[] args) throws ioexception { final string imagefile = "/tmp/page0.png"; final bufferedimage pngimage = imageio.read(new file(imagefile)); // convert png jpeg // http://www.mkyong.com/java/convert-png-to-jpeg-image-file-in-java/ final bufferedimage rgbimage = new bufferedimage(pngimage.getwidth(), pngimage.getheight(), bufferedimage.type_int_rgb); rgbimage.creategraphics().drawimage(pngimage, 0, 0, color.white, null); // rgb cmyk using colorconvertop // https://stackoverflow.com/questions/380678/how-to-set-icc-color-profile-in-java-and-change-colorspace/2804370#2804370 final icc_profile ip = icc_profile.getinstance("icc/isocoated_v2_300_eci.icc"); // final icc_profile ip = icc_profile.getinstance("icc/coatedfogra27.icc"); // final icc_profile ip = icc_profile.getinstance("icc/uswebuncoated.icc"); final colorconvertop cco = new colorconvertop(new icc_colorspace(ip), null); final bufferedimage cmykimage = cco.filter(rgbimage, null); // write result bytearray final bytearrayoutputstream baos = new bytearrayoutputstream(); imageio.write(cmykimage, "jpg", baos); baos.flush(); final byte[] imageinbyte = baos.tobytearray(); }
the problem is, leads me exception:
exception in thread "main" javax.imageio.iioexception: invalid argument native writeimage @ com.sun.imageio.plugins.jpeg.jpegimagewriter.writeimage(native method) @ com.sun.imageio.plugins.jpeg.jpegimagewriter.writeonthread(jpegimagewriter.java:1058) @ com.sun.imageio.plugins.jpeg.jpegimagewriter.write(jpegimagewriter.java:360) @ javax.imageio.imagewriter.write(imagewriter.java:615) @ javax.imageio.imageio.dowrite(imageio.java:1612) @ javax.imageio.imageio.write(imageio.java:1578) @ ... .pdf.reportgeneratorpubliccontenttest.main(reportgeneratorpubliccontenttest.java:69)
the message of exception doesn't me. on this thread sun jdk or jai fix problem.
i tried apt-get install libjai-core-java
, oracle jdk jdk1.7.0_51
. error still persists.
@christian schneider : after download image file link of cmyk jpeg, open file's property. see color space of image still rgb. picture isn't converted cmyk color. please see below link :
how can convert rgb image cmyk , vice versa in java?
lovelywib 's answer solved this.
Comments
Post a Comment