List of usage examples for org.jfree.chart ChartPanel getBackground
@Transient
public Color getBackground()
From source file:script.imglib.analysis.ChartUtils.java
public static final Image<RGBALegacyType> asImage(final JFreeChart chart, int width, int height) { ChartPanel panel = new ChartPanel(chart); Dimension d = panel.getPreferredSize(); if (-1 == width && -1 == height) { width = d.width;// w ww . ja va2s . c o m height = d.height; panel.setSize(d); } else { panel.setSize(width, height); } layoutComponent(panel); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); if (!panel.isOpaque()) { g.setColor(panel.getBackground()); g.fillRect(0, 0, width, height); } panel.paint(g); int[] pixels = new int[width * height]; PixelGrabber pg = new PixelGrabber(bi, 0, 0, width, height, pixels, 0, width); try { pg.grabPixels(); } catch (InterruptedException e) { } g.dispose(); Array<RGBALegacyType, IntAccess> a = new Array<RGBALegacyType, IntAccess>(new ArrayContainerFactory(), new IntArray(pixels), new int[] { width, height }, 1); // create a Type that is linked to the container final RGBALegacyType linkedType = new RGBALegacyType(a); // pass it to the DirectAccessContainer a.setLinkedType(linkedType); return new Image<RGBALegacyType>(a, new RGBALegacyType()); }
From source file:net.imglib2.script.analysis.ChartUtils.java
public static final Img<ARGBType> asImage(final JFreeChart chart, int width, int height) { final ChartPanel panel = new ChartPanel(chart); final Dimension d = panel.getPreferredSize(); if (-1 == width && -1 == height) { width = d.width;/* www.j a v a2s . c om*/ height = d.height; panel.setSize(d); } else { panel.setSize(width, height); } layoutComponent(panel); final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = bi.createGraphics(); if (!panel.isOpaque()) { g.setColor(panel.getBackground()); g.fillRect(0, 0, width, height); } panel.paint(g); final int[] pixels = new int[width * height]; final PixelGrabber pg = new PixelGrabber(bi, 0, 0, width, height, pixels, 0, width); try { pg.grabPixels(); } catch (final InterruptedException e) { } g.dispose(); final ArrayImg<ARGBType, IntArray> a = new ArrayImg<ARGBType, IntArray>(new IntArray(pixels), new long[] { width, height }, 1); // create a Type that is linked to the container final ARGBType linkedType = new ARGBType(a); // pass it to the DirectAccessContainer a.setLinkedType(linkedType); return a; }