集册 Java实例教程 创建默认的单色位图转换器

创建默认的单色位图转换器

欢马劈雪     最近更新时间:2020-01-02 10:19:05

583
创建默认的单色位图转换器

/*

 * Licensed to the Apache Software Foundation (ASF) under one or more

 * contributor license agreements.  See the NOTICE file distributed with

 * this work for additional information regarding copyright ownership.

 * The ASF licenses this file to You 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.

 *///N o w J a v a . c o m - 时代Java

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Graphics2D;

import java.awt.geom.AffineTransform;

import java.awt.image.BufferedImage;

import java.awt.image.ColorModel;

import java.awt.image.IndexColorModel;

import java.awt.image.RenderedImage;

import java.awt.image.WritableRaster;


public class Main{

    public static void main(String[] argv) throws Exception{

        System.out.println(createDefaultMonochromeBitmapConverter());

    }

    /** @return the bitmap converter */

    public static MonochromeBitmapConverter createDefaultMonochromeBitmapConverter() {

        MonochromeBitmapConverter converter = null;

        try {

            final String clName = "org.apache.fop.util.bitmap.JAIMonochromeBitmapConverter";

            final Class clazz = Class.forName(clName);
            /**来自 
             时 代 J a v a 公 众 号 - N o w J a v  a . c o m**/

            converter = (MonochromeBitmapConverter) clazz.newInstance();

        } catch (final ClassNotFoundException cnfe) {

            // Class was not compiled so is not available. Simply ignore.

        } catch (final LinkageError le) {

            // This can happen if fop was build with support for a

            // particular provider (e.g. a binary fop distribution)

            // but the required support files (i.e. JAI) are not

            // available in the current runtime environment.

            // Simply continue with the backup implementation.

        } catch (final InstantiationException e) {

            
展开阅读全文