import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;
import javax.imageio.*;
import javax.swing.*;
public class CreateImage extends Component{
BufferedImage img;
int pixel = 265*190;
int steg = 3;
int p,s;
int [][] rgb_steg = new int [pixel][steg];
public CreateImage()throws Exception{
try{
img = ImageIO.read(new File("cover-fruits.jpg"));
}catch (IOException e){
}
File f = new File("stego_rgb.txt");
if(!(f.exists())){
System.out.println("Sorry file are not exist");
System.exit(0);
}
Scanner in = new Scanner(f);
String data = null;
int rgb = 0;
int rgb1 = 0;
p=0;
while(in.hasNextInt()){
data = in.nextLine();
StringTokenizer st = new StringTokenizer(data," ");
for(s=0;s<steg;s++){
rgb = Integer.parseInt(st.nextToken());
rgb_steg[p][s] = rgb;
rgb1 = rgb_steg[p][s];
}
p++;
}
for(int y = 0 ; y <img.getHeight() ; y++){
for(int x = 0; x < img.getWidth() ; x++){
img.setRGB(x, y, rgb1);
}
}
File output = new File("saved.png");
ImageIO.write(img , "png", output);
img = ImageIO.read(new File("saved.png"));
}
public static void main(String[] args) throws Exception{
JFrame f = new JFrame("Load Image");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
f.add(new CreateImage());
f.pack();
f.setVisible(true);
}
}
我正在尝试从 .txt 读取 RGB 值并创建图像。但我没能做到。我对从像素值创建图像有一些想法, 但仍然无法得到它。希望任何人都可以帮助我。