0

Basically I need to extract CMYK color values from a byte array containing image data (tif image). I am not interested in converting the values to rgb colorspase. I just need to extract the cyan, magenta, yellow, and key (black) values (ideally in hex but beggars can not by choosers). Can libraries like JAI or imageIO help me do that?

Edit : In line with the comments I received I tried the following

   Raster r = renderedImage.getData();
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
           for(int i =0; i<r.getWidth();i++ ){
               for(int j = 0; j<r.getHeight();j++){
                  baos.write((byte)r.getSample(i,j,0));
               }
           }
       byte [] cyanBand = baos.toByteArray();

However, the resulting values in the array do not look correct. I am following the correct approach?

Any ideas would be more than welcomed .

Thanks in advance

user1479847
  • 107
  • 11
  • Related question - http://stackoverflow.com/questions/4858131/rgb-to-cmyk-and-back-algorithm – Gilbert Le Blanc Nov 29 '13 at 21:07
  • @Gilbert Le Blanc In order to get the CMYK values I want, is converting from rgb the only/easiest option? – user1479847 Nov 29 '13 at 21:13
  • Yes, it's the only option. – Gilbert Le Blanc Nov 29 '13 at 22:04
  • For clarification: your input image *is* in RGB? TIFF images usually only store the data in one color space. – Jongware Nov 29 '13 at 22:14
  • @Jongware The input image colorspace is CMYK. I just do not know how to extract the four color values/arrays – user1479847 Nov 30 '13 at 11:30
  • Ah, so you don't have to do the conversion yourself. Then you only need to access the raw image data, and I suppose either of the libraries you mention can give you that. Reading raw TIFF data is well documented, but there are *lots* of data variants. A good library shields you from all the gritty low level details. – Jongware Nov 30 '13 at 12:37
  • Yes, `ImageIO` can help you read the data in its original layout (use `ImageReader.readRaster()`). If the image data is CMYK, you will be able to access the CMYK data. ImageIO will not read TIFF by default. You will need a TIFF plugin, either jai-imageio or another 3rd party plugin. – Harald K Dec 01 '13 at 15:38

0 Answers0