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.FileInputStream;
22 import java.io.FileNotFoundException;
23 import java.io.IOException;
24 import java.io.InputStream;
27 import org.apache.batik.transcoder.TranscoderException;
29 import org.hedgecode.chess.img.ImageException;
30 import org.hedgecode.chess.img.ImageShaper;
33 * Shaper for vector images.
35 * @author Dmitry Samoshin aka gotty
37 public class VectorImageShaper implements ImageShaper {
39 private VectorImageShaper() {
43 public BufferedImage shape(InputStream imageStream, int size) throws ImageException {
44 SquareImageTranscoder imageTranscoder =
45 new SquareImageTranscoder(BufferedImage.TYPE_INT_ARGB, size);
47 return imageTranscoder.transcode(imageStream);
48 } catch (TranscoderException e) {
49 throw new ImageException("image.unable.load.vector", e.getMessage());
54 public BufferedImage shape(URL imageUrl, int size) throws ImageException {
57 imageUrl.openStream(),
60 } catch (IOException e) {
61 throw new ImageException("image.unable.load.vector", e.getMessage());
66 public BufferedImage shape(File imageFile, int size) throws ImageException {
69 new FileInputStream(imageFile),
72 } catch (FileNotFoundException e) {
73 throw new ImageException("image.unable.load.vector", e.getMessage());
77 public static ImageShaper create() {
78 return new VectorImageShaper();