4

I have a Bitmap in CMYK mode, which doesn't show correctly, and at some point not at all, on Android. Googling didn't return many answers, so I have to ask here how do I handle CMYK mode images?

Thanks

UPDATE

Ok, more info as requested. I have a image that is in the assets, and I construct a Bitmap out of it. Then when I construct the Bitmap I do it like:

Bitmap bm = Bitmap.createBitmap(width, height, Config.ARGB_8888);

The Image is in CMYK mode. When I put it on a ImageView - it appears as white box. Not shown.

Hope this helps.

Pett
  • 171
  • 5
  • 7
  • 2
    How do you expect anyone to help with such a vague question. 'Handle'? 'doesn't show correctly...not at all'? What form would you expect an answer to take here? –  Jul 08 '11 at 13:32
  • Please provide more specifics: What have you tried, have you identified any commonality between the situations that don't work, and when the display is wrong HOW is it wrong? – jefflunt Jul 08 '11 at 13:36

4 Answers4

0

I made it! I found a nice tool for correct handling *.jpg files on Android platform with uncommon colorspaces like CMYK, YCCK and so on. Use https://github.com/puelocesar/android-lib-magick, it's free and easy to configure android library. Here is a snippet for converting CMYK images to RGB colorspace:

ImageInfo info = new ImageInfo(Environment.getExternalStorageDirectory().getAbsolutePath() + "/cmyk.jpg");
MagickImage imageCMYK = new MagickImage(info);

Log.d(TAG, "ColorSpace BEFORE => " + imageCMYK.getColorspace());
boolean status = imageCMYK.transformRgbImage(ColorspaceType.CMYKColorspace);
Log.d(TAG, "ColorSpace AFTER => " + imageCMYK.getColorspace() + ", success = " + status);

imageCMYK.setFileName(Environment.getExternalStorageDirectory().getAbsolutePath() + "/cmyk_new.jpg");
imageCMYK.writeImage(info);
Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath()
            + "/Docs/cmyk_new.jpg");
if (bitmap == null) {
    //if decoding fails, create empty image 
    bitmap = Bitmap.createBitmap(imageCMYK.getWidth(), imageCMYK.getHeight(), Config.ARGB_8888);
}    
ImageView imageView1 = (ImageView) findViewById(R.id.imageView1);
imageView1.setImageBitmap(bitmap);
kord
  • 482
  • 3
  • 12
0

I also used the library from https://github.com/puelocesar/android-lib-magick Below is my code, u dont need to create new file on storage:

try {
        ImageInfo info = new ImageInfo(Environment.getExternalStorageDirectory().getAbsolutePath() + "/cmyk.jpg");
        MagickImage image = new MagickImage(info);

        if(image.getColorspace() == ColorspaceType.CMYKColorspace) {
            Log.e("ImageMagick", "ColorSpace BEFORE => " + image.getColorspace());
            boolean status = image.transformRgbImage(ColorspaceType.CMYKColorspace);
            Log.e("ImageMagick", "ColorSpace AFTER => " + image.getColorspace() + ", success = " + status);
        }

        Bitmap bitmap = MagickBitmap.ToBitmap(image);
        Log.e("ImageMagick", "bitmap is " + bitmap);
        ivCMYK.setImageBitmap(bitmap);
    } catch (MagickException e) {
        Log.e("MagickException", e.getMessage());
    }
Co-Gia
  • 103
  • 2
  • 10
0

Here is an example code using android-lib-magick to display an image with CMYK colorspare (not supported by Android), which is got from an URL.

https://github.com/Mariovc/GetCMYKImage

There are two methods called "getCMYKImageFromPath" and "getCMYKImageFromURL".

Mario Velasco
  • 3,336
  • 3
  • 33
  • 50
0

CMYK is a format for PRINTING. All "standard" structures , such as jpeg, bitmaps and so on, are for a SCREEN, and read your structure as if it were RGB. Put the result in PDF or other postscript and you'll see it OK.

Gangnus
  • 24,044
  • 16
  • 90
  • 149