2 * Copyright (c) 2018-2019. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.img.vector;
19 import java.awt.image.BufferedImage;
21 import java.io.IOException;
22 import java.io.InputStream;
24 import javax.imageio.ImageIO;
26 import org.apache.batik.transcoder.TranscoderException;
27 import org.apache.batik.transcoder.TranscoderInput;
28 import org.apache.batik.transcoder.TranscoderOutput;
29 import org.apache.batik.transcoder.image.ImageTranscoder;
31 import org.hedgecode.chess.img.ImageFormat;
34 * Transcoder for vector square images to {@link BufferedImage}.
36 * @author Dmitry Samoshin aka gotty
37 * @see ImageTranscoder
39 public class SquareImageTranscoder extends ImageTranscoder {
41 private final int type;
42 private BufferedImage image;
44 SquareImageTranscoder(int type) {
48 SquareImageTranscoder(int type, int size) {
50 addTranscodingHint(ImageTranscoder.KEY_WIDTH, (float) size);
51 addTranscodingHint(ImageTranscoder.KEY_HEIGHT, (float) size);
56 protected void setImageSize(float width, float height) {
57 if (width > 0 && height > 0) {
58 super.setImageSize(width, height);
63 public BufferedImage createImage(int width, int height) {
64 return new BufferedImage(width, height, type);
68 public void writeImage(BufferedImage image, TranscoderOutput to) throws TranscoderException {
72 public BufferedImage transcode(InputStream inputStream) throws TranscoderException {
74 new TranscoderInput(inputStream),
80 public BufferedImage getImage() {
85 public static void main(String[] args) throws TranscoderException, IOException {
86 SquareImageTranscoder imageTranscoder =
87 new SquareImageTranscoder(BufferedImage.TYPE_INT_ARGB); // , 250
89 imageTranscoder.transcode(
90 ClassLoader.getSystemResourceAsStream("images/pieces/spatial/bb.svg")
92 ImageFormat.PNG.name(),
93 new File("bishop" + "." + ImageFormat.PNG.getExt())