Tutorial by Examples

class ImageCreationExample { static Image createSampleImage() { // instantiate a new BufferedImage (subclass of Image) instance BufferedImage img = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB); //draw something on the image paintOnI...
public static void saveImage(String destination) throws IOException { // method implemented in "Creating a simple image Programmatically and displaying it" example BufferedImage img = createSampleImage(); // ImageIO provides several write methods with different outputs ...
static void setupQualityHigh(Graphics2D g2d) { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // many other RenderingHints KEY/VALUE pairs to specify } ...
int width = 256; //in pixels int height = 256; //in pixels BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); //BufferedImage.TYPE_4BYTE_ABGR - store RGB color and visibility (alpha), see javadoc for more info Graphics g = image.createGraphics(); //draw w...
BufferedImage cat = ImageIO.read(new File("cat.jpg")); //read existing file //modify it Graphics g = cat.createGraphics(); g.setColor(Color.RED); g.drawString("Cat", 10, 10); g.dispose(); //now create a new image BufferedImage cats = new BufferedImage(256, 256, Buffere...
BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); //you don't have to use the Graphics object, you can read and set pixel color individually for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { int alpha = 255; //don't forget this, or ...
/** * Resizes an image using a Graphics2D object backed by a BufferedImage. * @param srcImg - source image to scale * @param w - desired width * @param h - desired height * @return - the new resized image */ private BufferedImage getScaledImage(Image srcImg, int w, int h){ //Cre...

Page 1 of 1