package jstenografer;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import jstenografer.exception.*;
public class Stenografer {
public static void write
(File pOpenFile,
String pSteno,
File pDestination
) throws IOException, TooLongStringException, NotBMPDestinationFile
{
if (pOpenFile.exists()) {
String nameFile
=pDestination.
getPath();
String ext
=nameFile.
substring(nameFile.
length()-3
);
if (pSteno.length() > img.getWidth() * img.getHeight()) {
throw new TooLongStringException();
}
if(!ext.equalsIgnoreCase("bmp")){
throw new NotBMPDestinationFile();
}
int w = 1;
int h = 0;
int r = color.getRed();
int g = color.getGreen();
int b = pSteno.length();
img.setRGB(0, 0, newColor.getRGB());
for (int i = 0; i < pSteno.length(); i++) {
color
= new Color(img.
getRGB(w, h
));
r = color.getRed();
g = color.getGreen();
b = (int) pSteno.charAt(i);
newColor
= new Color(r, g, b
);
img.setRGB(w, h, newColor.getRGB());
w++;
if (w >= img.getWidth()) {
w = 0;
h++;
}
}
ImageIO.write(img, "bmp", pDestination);
}
}
if (pOpenFile.exists()) {
int leng=color.getBlue();
int w=1;
int h=0;
char lett;
for(int i=0; i<leng; i++){
color
=new Color(img.
getRGB(w, h
));
lett=(char)color.getBlue();
retval+=lett;
w++;
if(w>=img.getWidth()){
w=0;
h++;
}
}
return retval;
}
return "";
}
}