1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| package org.example;
import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO;
public class GradientImage { public static void main(String[] args) throws Exception { int width = 400; int height = 200;
saveGradientImage("#0062be", "#925696", "#cc426e", "#fb0347", "default");
saveGradientImage("#ff9a9e", "#fad0c4", "#fad0c4", null, "romantic_pink");
saveGradientImage("#232526", "#414345", "#5e6062", null, "mysterious_night");
saveGradientImage("#56ab2f", "#a8e063", "#76ba1b", null, "tropical_rainforest");
saveGradientImage("#accbee", "#e7f0fd", "#ffffff", null, "frosty_morning");
saveGradientImage("#e6e9af", "#e8c37e", "#f4d03f", null, "golden_beach");
saveGradientImage("#DA22FF", "#9733EE", "#65799B", "#5E2563", "dreamy_violet");
saveGradientImage("#0f2027", "#203a43", "#2c5364", null, "deep_space");
saveGradientImage("#9be15d", "#00e3ae", "#88d8b0", null, "fresh_meadow");
saveGradientImage("#ff7e5f", "#feb47b", "#ff7e5f", "#fcb045", "sunset_dusk");
saveGradientImage("#2e8b57", "#48d1cc", "#00ced1", "#7fffd4", "calm_ocean_breeze");
saveGradientImage("#3e5151", "#decba4", null, null, "serene_forest");
saveGradientImage("#2E3192", "#1BFFFF", null, null, "mysterious_sea");
saveGradientImage("#ee9ca7", "#ffdde1", null, null, "evening_glow");
saveGradientImage("#FF5F6D", "#FFC371", null, null, "morning_glow");
saveGradientImage("#000428", "#004e92", null, null, "winter_aurora");
saveGradientImage("#D9AFD9", "#97D9E1", null, null, "prairie_sunset");
saveGradientImage("#0f0c29", "#302b63", "#24243e", null, "starry_galaxy");
saveGradientImage("#C9FFBF", "#FFAFBD", "#FFF", null, "morning_dew");
saveGradientImage("#FFB75E", "#ED8F03", null, null, "warm_sunshine");
saveGradientImage("#5f2c82", "#49a09d", null, null, "tranquil_blue_sky"); }
private static void saveGradientImage(String color1, String color2, String color3, String color4, String imageName) throws Exception { int width = 400; int height = 200;
GradientPaint gradient;
if (color4 != null) { gradient = new GradientPaint(0, 0, Color.decode(color1), width, height, Color.decode(color4)); } else if (color3 != null) { gradient = new GradientPaint(0, 0, Color.decode(color1), width, height, Color.decode(color3)); } else { gradient = new GradientPaint(0, 0, Color.decode(color1), width, height, Color.decode(color2)); }
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
g2d.setPaint(gradient); g2d.fillRect(0, 0, width, height);
ImageIO.write(image, "png", new File("/Users/raccoon/Desktop/Wallpapers/400x200/" + imageName + ".png")); } }
|