Java examples for Language Basics:Bit
create Default Monochrome Bitmap Converter
/*//from ww w . j a v a2s . c om * 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. */ 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); 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) { // Problem instantiating the class, simply continue with the backup // implementation } catch (final IllegalAccessException e) { // Problem instantiating the class, simply continue with the backup // implementation } if (converter == null) { converter = new DefaultMonochromeBitmapConverter(); } return converter; } }