KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > pcl > DefaultMonochromeBitmapConverter


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id$ */
19
20 package org.apache.fop.render.pcl;
21
22 import java.awt.RenderingHints JavaDoc;
23 import java.awt.color.ColorSpace JavaDoc;
24 import java.awt.image.BufferedImage JavaDoc;
25 import java.awt.image.ColorConvertOp JavaDoc;
26 import java.awt.image.RenderedImage JavaDoc;
27
28 /**
29  * Default implementation of the MonochromeBitmapConverter which uses the Java Class Library
30  * to convert grayscale bitmaps to monochrome bitmaps.
31  */

32 public class DefaultMonochromeBitmapConverter implements
33         MonochromeBitmapConverter {
34
35     /** @see MonochromeBitmapConverter#setHint(java.lang.String, java.lang.String) */
36     public void setHint(String JavaDoc name, String JavaDoc value) {
37         //ignore, not supported
38
}
39     
40     /** @see MonochromeBitmapConverter#convertToMonochrome(java.awt.image.BufferedImage) */
41     public RenderedImage JavaDoc convertToMonochrome(BufferedImage JavaDoc img) {
42         BufferedImage JavaDoc buf = new BufferedImage JavaDoc(img.getWidth(), img.getHeight(),
43                 BufferedImage.TYPE_BYTE_BINARY);
44         RenderingHints JavaDoc hints = new RenderingHints JavaDoc(null);
45         //This hint doesn't seem to make a difference :-(
46
hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
47         ColorConvertOp JavaDoc op = new ColorConvertOp JavaDoc(
48                 ColorSpace.getInstance(ColorSpace.CS_GRAY), hints);
49         op.filter(img, buf);
50         return buf;
51     }
52
53 }
54
Popular Tags