List of usage examples for java.awt.image DataBufferInt getNumBanks
public int getNumBanks()
From source file:net.bioclipse.chart.ChartUtils.java
/** * Utility method for converting JFreeChart to an image * @param parent used for color correction * @param chart the chart to be made into an image * @param width image width/* ww w . java 2 s. c o m*/ * @param height image height * @return SWT Image of the chart */ public static Image createChartImage(Composite parent, JFreeChart chart, int width, int height) { // Color adjustment Color swtBackground = parent.getBackground(); java.awt.Color awtBackground = new java.awt.Color(swtBackground.getRed(), swtBackground.getGreen(), swtBackground.getRed()); chart.setBackgroundPaint(awtBackground); // Draw the chart in an AWT buffered image BufferedImage bufferedImage = chart.createBufferedImage(width, height, null); // Get the data buffer of the image DataBuffer buffer = bufferedImage.getRaster().getDataBuffer(); DataBufferInt intBuffer = (DataBufferInt) buffer; // Copy the data from the AWT buffer to a SWT buffer PaletteData paletteData = new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF); ImageData imageData = new ImageData(width, height, 32, paletteData); for (int bank = 0; bank < intBuffer.getNumBanks(); bank++) { int[] bankData = intBuffer.getData(bank); imageData.setPixels(0, bank, bankData.length, bankData, 0); } // Create an SWT image return new Image(parent.getDisplay(), imageData); }