2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015 - Marcos CARDINOT
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 package org.scilab.modules.xcos.utils;
15 import java.awt.image.BufferedImage;
17 import javax.swing.ImageIcon;
19 import org.apache.batik.transcoder.TranscoderException;
20 import org.apache.batik.transcoder.TranscoderOutput;
21 import org.apache.batik.transcoder.image.ImageTranscoder;
24 * A simple transcoder that can be used to generate ImageIcon and BufferedImage.
25 * @author Marcos Cardinot <mcardinot@gmail.com>
27 public class ImageIconTranscoder extends ImageTranscoder {
28 private BufferedImage bufferedImage;
29 private ImageIcon imgIcon;
34 public ImageIconTranscoder() {
38 * Creates a new ARGB image with the specified dimension.
39 * @param width the image width
40 * @param height the image height
41 * @return BufferedImage
43 public BufferedImage createImage(int width, int height) {
44 return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
49 * @param img the image to write
50 * @param output the output where to store the image
51 * @throws TranscoderException if an error occurred while storing the image
53 public void writeImage(BufferedImage img, TranscoderOutput output)
54 throws TranscoderException {
56 imgIcon = new ImageIcon(img);
60 * Get the image in BufferedImage format
61 * @return BufferedImage
63 public BufferedImage getBufferedImage() {
68 * Get the image in ImageIcon format
71 public ImageIcon getImageIcon() {
76 * Set the dimension of the image.
77 * @param width the image width
78 * @param height the image height
80 public void setDimensions(int width, int height) {
81 hints.put(KEY_WIDTH, new Float(width));
82 hints.put(KEY_HEIGHT, new Float(height));