Прочитать профиль TIFF ICC с помощью Twelvemonkeys ImageIO - PullRequest
0 голосов
/ 15 января 2019

Мне нужно извлечь встроенный профиль ICC из файлов TIFF. Я могу прочитать IIOMetadata, и моя IDE показывает поле ifd, содержащее профиль ICC (идентификатор тега 34675). Но как я могу прочитать его на ICC_Profile объекте?

ImageInputStream input = ImageIO.createImageInputStream(file);

try {
    ImageReader reader = ImageIO.getImageReaders(input).next();
    if (reader == null) {
        throw new IllegalArgumentException("No image reader for file: " + file);
    }

    try {
        reader.setInput(input);
        IIOMetadata metadata = reader.getImageMetadata(0);
        // metadata contains a field "ifd" containing the ICC profile
        // How to extract it?

    } finally {
        reader.dispose();
    }

} finally {
    input.close();
}

Ответы [ 2 ]

0 голосов
/ 15 января 2019

Нашел решение. Для этого требуется пакет Twelvemonkeys imageio-metadata в версии 3.4. Старая версия не содержит TIFFEntry класс.

 /**
 * Extract ICC profile from an image file.
 *
 * @param file image file
 * @return ICC profile
 * @throws IOException on file errors
 */
protected ICC_Profile extractICCProfile(File file) throws IOException {

    ICC_Profile profile;

    try (ImageInputStream input = ImageIO.createImageInputStream(file)) {
        ImageReader reader = ImageIO.getImageReaders(input).next();
        if (reader == null) {
            throw new IllegalArgumentException("No image reader for file: " + file);
        }

        try {
            reader.setInput(input);
            TIFFImageMetadata metadata = (TIFFImageMetadata) reader.getImageMetadata(0);
            TIFFEntry entry = (TIFFEntry) metadata.getTIFFField(TIFF.TAG_ICC_PROFILE);
            byte[] iccBytes = (byte[]) entry.getValue();
            profile = ICC_Profile.getInstance(iccBytes);
        } finally {
            reader.dispose();
        }
    }

    return profile;
}
0 голосов
/ 15 января 2019

Вы можете использовать функцию getProfile() класса ICCProfile.

Использование:

int profileId = ...; 
ICCProfile iccp = new ICCProfile(profileId, input);
ICC_Profile icc_p = iccp.getProfile();

В соответствии с кодом на google result # 1 for twelvemonkeys icc_profile .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...