All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.krysalis.barcode4j.image.loader.ImageLoaderBarcode Maven / Gradle / Ivy

Go to download

This module contains SPI implementation for Apache XML-Graphics barcode images

The newest version!
/*
 * Copyright 2008,2010 Jeremias Maerki.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id: ImageLoaderBarcode.java,v 1.1 2010-11-18 09:34:22 jmaerki Exp $ */

package org.krysalis.barcode4j.image.loader;

import java.io.IOException;
import java.util.Map;

import org.apache.xmlgraphics.image.loader.Image;
import org.apache.xmlgraphics.image.loader.ImageException;
import org.apache.xmlgraphics.image.loader.ImageFlavor;
import org.apache.xmlgraphics.image.loader.ImageInfo;
import org.apache.xmlgraphics.image.loader.ImageSessionContext;
import org.apache.xmlgraphics.image.loader.impl.AbstractImageLoader;

/**
 * ImageLoader for barcodes. This implementation doesn't really load anything since the full
 * barcode has to be loaded and pre-processed at preloading time.
 */
public class ImageLoaderBarcode extends AbstractImageLoader {

    private ImageFlavor targetFlavor;

    /**
     * Main constructor.
     * @param targetFlavor the target flavor
     */
    public ImageLoaderBarcode(ImageFlavor targetFlavor) {
        if (!(targetFlavor.isCompatible(ImageBarcode.BARCODE_IMAGE_FLAVOR))) {
            throw new IllegalArgumentException("Unsupported target ImageFlavor: " + targetFlavor);
        }
        this.targetFlavor = targetFlavor;
    }

    /** {@inheritDoc} */
    @Override
    public ImageFlavor getTargetFlavor() {
        return this.targetFlavor;
    }

    /** {@inheritDoc} */
    @Override
    public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session)
                throws ImageException, IOException {
        Image img = info.getOriginalImage();
        if (!(img instanceof ImageBarcode)) {
            throw new IllegalArgumentException(
                    "ImageInfo was expected to contain the Barcode document");
        }
        ImageBarcode barcodeImage = (ImageBarcode)img;
        return barcodeImage;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy