Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.GradientPaint;
- import java.awt.Graphics2D;
- import java.awt.RenderingHints;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- public class TestImageIo {
- public static void main(String[] args) {
- TestImageIo testImageIo = new TestImageIo();
- BufferedImage img = testImageIo.imageCreate(600, 600);
- testImageIo.save3(img);
- }
- public BufferedImage imageCreate(int width, int height) {
- BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g2 = img.createGraphics();
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);;
- int x2 = width / 10;
- int y2 = height / 10;
- GradientPaint gPaint = new GradientPaint(0, 0, Color.RED, x2, y2, Color.BLUE, true);
- g2.setPaint(gPaint);
- g2.fillOval(5, 5, width - 10, height - 10);
- g2.dispose();
- return img;
- }
- public void save3(BufferedImage img) {
- File out = new File("hello.png");
- try {
- ImageIO.write(img, "png", out);
- } catch (IOException e2) {
- System.out.println(e2);
- }
- }
- }
Add Comment
Please, Sign In to add comment