Create a BufferedImage from file and make it TYPE_INT_RGB
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
public class Main{
public static void main(String args[]){
try{
BufferedImage img = new BufferedImage(
500, 500, BufferedImage.TYPE_INT_RGB );
File f = new File("MyFile.png");
int r = 5;
int g = 25;
int b = 255;
int col = (r << 16) | (g << 8) | b;
for(int x = 0; x < 500; x++){
for(int y = 20; y < 300; y++){
img.setRGB(x, y, col);
}
}
ImageIO.write(img, "PNG", f);
}
catch(Exception e){
e.printStackTrace();
}
}
}
这在顶端描述了一个大的蓝.。
www.un.org/spanish/ecosoc 如果你想要的话,我们就这样做了:。
try{
BufferedImage img = new BufferedImage(
500, 500, BufferedImage.TYPE_INT_ARGB );
File f = new File("MyFile.png");
int r = 255;
int g = 10;
int b = 57;
int alpha = 255;
int col = (alpha << 24) | (r << 16) | (g << 8) | b;
for(int x = 0; x < 500; x++){
for(int y = 20; y < 30; y++){
img.setRGB(x, y, col);
}
}
ImageIO.write(img, "PNG", f);
}
catch(Exception e){
e.printStackTrace();
}
Open up MyFile.png, it has a red streak across the top.