久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 ColdFusion (Java) 中在 CMYK 和 RGB 之間轉(zhuǎn)換圖

How do I convert images between CMYK and RGB in ColdFusion (Java)?(如何在 ColdFusion (Java) 中在 CMYK 和 RGB 之間轉(zhuǎn)換圖像?)
本文介紹了如何在 ColdFusion (Java) 中在 CMYK 和 RGB 之間轉(zhuǎn)換圖像?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我需要將圖像從 CMYK 轉(zhuǎn)換為 RGB - 不一定要再轉(zhuǎn)換回來(lái),但是嘿,如果可以的話...

I have a need to convert images from CMYK to RGB - not necessarily back again, but hey, if it can be done...

隨著 ColdFusion 8 的發(fā)布,我們獲得了 CFImage 標(biāo)簽,但它沒(méi)有'不支持這種轉(zhuǎn)換;Image.cfc 或 Alagad 的圖像組件.

With the release of ColdFusion 8, we got the CFImage tag, but it doesn't support this conversion; and nor does Image.cfc, or Alagad's Image Component.

但是,在 Java 中應(yīng)該是可能的;我們可以通過(guò) CF 加以利用.例如,以下是創(chuàng)建 Java 線程來(lái)休眠進(jìn)程的方法:

However, it should be possible in Java; which we can leverage through CF. For example, here's how you might create a Java thread to sleep a process:

<cfset jthread = createObject("java", "java.lang.Thread")/>
<cfset jthread.sleep(5000)/>

我猜想可以使用類似的方法來(lái)利用 java 進(jìn)行這種圖像轉(zhuǎn)換,但不是 Java 開(kāi)發(fā)人員,我不知道從哪里開(kāi)始.有人可以幫忙嗎?

I would guess a similar method could be used to leverage java to do this image conversion, but not being a Java developer, I don't have a clue where to start. Can anyone lend a hand here?

推薦答案

我使用 Java ImageIO 庫(kù) (https://jai-imageio.dev.java.net).它們并不完美,但可以很簡(jiǎn)單并完成工作.至于從 CMYK 轉(zhuǎn)換為 RGB,這是我能想到的最好的.

I use the Java ImageIO libraries (https://jai-imageio.dev.java.net). They aren't perfect, but can be simple and get the job done. As far as converting from CMYK to RGB, here is the best I have been able to come up with.

為您的平臺(tái)下載并安裝 ImageIO JAR 和本機(jī)庫(kù).本機(jī)庫(kù)是必不可少的.沒(méi)有它們,ImageIO JAR 文件將無(wú)法檢測(cè) CMYK 圖像.最初,我的印象是本機(jī)庫(kù)會(huì)提高性能,但不需要任何功能.我錯(cuò)了.

Download and install the ImageIO JARs and native libraries for your platform. The native libraries are essential. Without them the ImageIO JAR files will not be able to detect the CMYK images. Originally, I was under the impression that the native libraries would improve performance but was not required for any functionality. I was wrong.

我注意到的另一件事是,轉(zhuǎn)換后的 RGB 圖像有時(shí)比 CMYK 圖像輕得多.如果有人知道如何解決這個(gè)問(wèn)題,我將不勝感激.

The only other thing that I noticed is that the converted RGB images are sometimes much lighter than the CMYK images. If anyone knows how to solve that problem, I would be appreciative.

以下是將 CMYK 圖像轉(zhuǎn)換為任何支持格式的 RGB 圖像的一些代碼.

Below is some code to convert a CMYK image into an RGB image of any supported format.

謝謝你,
蘭迪·施泰格鮑爾

Thank you,
Randy Stegbauer

package cmyk;

import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.commons.lang.StringUtils;

public class Main
{

    /**
     * Creates new RGB images from all the CMYK images passed
     * in on the command line.
     * The new filename generated is, for example "GIF_original_filename.gif".
     *
     */
    public static void main(String[] args)
    {
        for (int ii = 0; ii < args.length; ii++)
        {
            String filename = args[ii];
            boolean cmyk = isCMYK(filename);
            System.out.println(cmyk + ": " + filename);
            if (cmyk)
            {
                try
                {
                    String rgbFile = cmyk2rgb(filename);
                    System.out.println(isCMYK(rgbFile) + ": " + rgbFile);
                }
                catch (IOException e)
                {
                    System.out.println(e.getMessage());
                }
            }
        }
    }

    /**
     * If 'filename' is a CMYK file, then convert the image into RGB,
     * store it into a JPEG file, and return the new filename.
     *
     * @param filename
     */
    private static String cmyk2rgb(String filename) throws IOException
    {
        // Change this format into any ImageIO supported format.
        String format = "gif";
        File imageFile = new File(filename);
        String rgbFilename = filename;
        BufferedImage image = ImageIO.read(imageFile);
        if (image != null)
        {
            int colorSpaceType = image.getColorModel().getColorSpace().getType();
            if (colorSpaceType == ColorSpace.TYPE_CMYK)
            {
                BufferedImage rgbImage =
                    new BufferedImage(
                        image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
                ColorConvertOp op = new ColorConvertOp(null);
                op.filter(image, rgbImage);

                rgbFilename = changeExtension(imageFile.getName(), format);
                rgbFilename = new File(imageFile.getParent(), format + "_" + rgbFilename).getPath();
                ImageIO.write(rgbImage, format, new File(rgbFilename));
            }
        }
        return rgbFilename;
    }

    /**
     * Change the extension of 'filename' to 'newExtension'.
     *
     * @param filename
     * @param newExtension
     * @return filename with new extension
     */
    private static String changeExtension(String filename, String newExtension)
    {
        String result = filename;
        if (filename != null && newExtension != null && newExtension.length() != 0);
        {
            int dot = filename.lastIndexOf('.');
            if (dot != -1)
            {
                result = filename.substring(0, dot) + '.' + newExtension;
            }
        }
        return result;
    }

    private static boolean isCMYK(String filename)
    {
        boolean result = false;
        BufferedImage img = null;
        try
        {
            img = ImageIO.read(new File(filename));
        }
        catch (IOException e)
        {
            System.out.println(e.getMessage() + ": " + filename);
        }
        if (img != null)
        {
            int colorSpaceType = img.getColorModel().getColorSpace().getType();
            result = colorSpaceType == ColorSpace.TYPE_CMYK;
        }

        return result;
    }
}

這篇關(guān)于如何在 ColdFusion (Java) 中在 CMYK 和 RGB 之間轉(zhuǎn)換圖像?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫(kù))
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 亚洲国产精品一区二区www | 亚洲国产二区 | 免费在线观看av的网站 | 久久国产精品视频 | 91精品免费 | 国产日韩欧美电影 | 免费在线观看一区二区三区 | 欧美激情欧美激情在线五月 | 色综合一区二区三区 | 欧美精品久久久 | 91精品国产综合久久久久久 | 久久精品国产一区二区 | 欧美国产精品久久久 | 91日日| 欧美日韩精品中文字幕 | 中国免费黄色片 | 秋霞电影一区二区三区 | 亚洲精品国产第一综合99久久 | 日韩欧美国产精品一区二区三区 | 日韩av三区 | 亚洲成人999 | 日韩中文字幕视频 | 精品免费视频一区二区 | 久久成人亚洲 | 影音先锋中文字幕在线观看 | 亚洲综合色网 | 久久精品综合网 | 色婷婷综合久久久中字幕精品久久 | 99亚洲国产精品 | 欧美日韩国产高清 | 91视频国产一区 | 日韩一区不卡 | 精品免费国产视频 | 日本三级日产三级国产三级 | 激情 亚洲 | 亚洲第一av网站 | 久久久国产精品 | 国产精品永久 | 99精品国产一区二区三区 | 亚洲午夜精品 | 97国产精品视频人人做人人爱 |