fubarable

Test Image

Dec 10th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.GradientPaint;
  3. import java.awt.Graphics2D;
  4. import java.awt.RenderingHints;
  5. import java.awt.image.BufferedImage;
  6. import java.io.File;
  7. import java.io.IOException;
  8. import javax.imageio.ImageIO;
  9.  
  10. public class TestImageIo {
  11.    
  12.     public static void main(String[] args) {
  13.         TestImageIo testImageIo = new TestImageIo();
  14.         BufferedImage img = testImageIo.imageCreate(600, 600);
  15.         testImageIo.save3(img);
  16.     }
  17.    
  18.     public BufferedImage imageCreate(int width, int height) {
  19.         BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  20.         Graphics2D g2 = img.createGraphics();
  21.         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);;
  22.         int x2 = width / 10;
  23.         int y2 = height / 10;
  24.         GradientPaint gPaint = new GradientPaint(0, 0, Color.RED, x2, y2, Color.BLUE, true);
  25.         g2.setPaint(gPaint);
  26.         g2.fillOval(5, 5, width - 10, height - 10);
  27.         g2.dispose();
  28.         return img;
  29.     }
  30.    
  31.     public void save3(BufferedImage img) {
  32.         File out = new File("hello.png");
  33.         try {
  34.             ImageIO.write(img, "png", out);
  35.         } catch (IOException e2) {
  36.             System.out.println(e2);
  37.         }
  38.     }
  39. }
Add Comment
Please, Sign In to add comment