Java tutorial
//package com.java2s; /***************************************************************************** ** ANGRYBIRDS AI AGENT FRAMEWORK ** Copyright (c) 2013,XiaoYu (Gary) Ge, Stephen Gould,Jochen Renz ** Sahan Abeyasinghe, Jim Keys, Kar-Wai Lim, Zain Mubashir, Andrew Wang, Peng Zhang ** All rights reserved. **This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. **To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ *or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. *****************************************************************************/ import java.awt.image.*; public class Main { public static BufferedImage int2image(int[][] scene) { int maxValue = -1; int minValue = Integer.MAX_VALUE; for (int y = 0; y < scene.length; y++) { for (int x = 0; x < scene[y].length; x++) { maxValue = Math.max(maxValue, scene[y][x]); minValue = Math.min(minValue, scene[y][x]); } } if (maxValue == minValue) maxValue = minValue + 1; final double scale = 255.0 / (maxValue - minValue); BufferedImage image = new BufferedImage(scene[0].length, scene.length, BufferedImage.TYPE_INT_RGB); for (int y = 0; y < scene.length; y++) { for (int x = 0; x < scene[y].length; x++) { final int c = (int) (scale * (scene[y][x] - minValue)); image.setRGB(x, y, c << 16 | c << 8 | c); } } return image; } }