安卓CMYK模式

发布于 2024-11-18 21:06:06 字数 354 浏览 3 评论 0原文

我有一个 CMYK 模式的位图,它在 Android 上无法正确显示,有时根本无法显示。谷歌搜索没有返回很多答案,所以我必须在这里问如何处理 CMYK 模式图像?

谢谢

更新

好的,根据要求提供更多信息。我在资源中有一张图像,我用它构建了一个位图。然后,当我构建位图时,我会这样做:

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

图像处于 CMYK 模式。 当我把它放在 ImageView 上时 - 它显示为白色框。未显示。

希望这有帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鹿! 2024-11-25 21:06:06

CMYK 是一种打印格式。所有“标准”结构,例如 jpeg、位图等,都是针对 SCREEN 的,并且可以像 RGB 一样读取您的结构。将结果放入 PDF 或其他 postscript 中,您就会看到它 OK。

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.

压抑⊿情绪 2024-11-25 21:06:06

我做到了!我发现了一个很好的工具,可以在 Android 平台上正确处理具有不常见色彩空间(如 CMYK、YCCK 等)的 *.jpg 文件。
使用 https://github.com/puelocesar/android-lib-magick,它是免费的并且易于配置android库。
以下是将 CMYK 图像转换为 RGB 色彩空间的片段:

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 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);
迷爱 2024-11-25 21:06:06

我还使用了 https://github.com/puelocesar/android-lib-magick
以下是我的代码,您不需要在存储上创建新文件:

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());
    }

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());
    }
夏有森光若流苏 2024-11-25 21:06:06

这里是使用 android-lib-magick 显示带有 CMYK 的图像colorspare(Android 不支持),从 URL 获取。

https://github.com/Mariovc/GetCMYKImage

有两种方法,称为“getCMYKImageFromPath”和“getCMYKImageFromURL” 。

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文