Android CMYK mode
I ha开发者_开发百科ve 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.
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.
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);
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());
}
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".
精彩评论