Click here to Skip to main content
15,848,157 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

i want to convert a cmyk type image into RGB Image.
if i use the below code the conversion happens but the image is not displaying properly.i can see block strike-through codes in my output image. any other way to convert CMYK to RGB.

java.util.Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
               ImageReader reader = null;
               while(readers.hasNext()) {
                   reader = (ImageReader);
                   if(reader.canReadRaster()) {

               //Stream the image file (the original CMYK image)
               ImageInputStream input =   ImageIO.createImageInputStream(fromFile);

               //Read the image raster
               Raster raster = reader.readRaster(0, null);

               //Create a new RGB image
               BufferedImage bi = new BufferedImage(raster.getWidth(), raster.getHeight(),BufferedImage.TYPE_INT_RGB);

               //Fill the new image with the old raster
           System.out.println("\n\n\n   bi.getColorModel().getColorSpace().getType()\n\n "+bi.getColorModel().getColorSpace().getType());

           //  BufferedImage bi =;
               int colorSpaceType = bi.getColorModel().getColorSpace().getType();

                if( colorSpaceType == ColorSpace.TYPE_CMYK)
                    System.out.println("\n\n\n is CMYK image \n\n\n");
                else if(colorSpaceType == ColorSpace.TYPE_RGB)
                System.out.println("\n\n\n is RGB image \n\n\n");
                ImageIO.write(bi, "JPEG", new File("d:\\hi.jpg"));


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900