Hello,
My question is how can I in java create a image and then save it?
Like pixel 100 = 0xFF665522 and then save it to png?
Thanks joaogl
Hello,
My question is how can I in java create a image and then save it?
Like pixel 100 = 0xFF665522 and then save it to png?
Thanks joaogl
There are a few ways, a simple one is:
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
public class SaveColor {
public static void save(int color) throws IOException {
int w = 1;
int h = 1;
BufferedImage bimg = new BufferedImage(w, h,
BufferedImage.TYPE_INT_ARGB);
bimg.setRGB(0, 0, color);
String fileName = "image.png";
File file = new File(fileName);
ImageIO.write(bimg, "png", file);
}
public static void main(String[] args) {
int color = 0xFF665522;
try {
save(color);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Thank you very much it worked just fine thanks