【发布时间】:2014-01-25 21:57:29
【问题描述】:
基于此的示例代码[已发布](Storing message into R,G,B instead of Alpha)
这次我只想使用 RGB 而不是 ARGB,但这次我收到的字节长度是 2147483647。下面是我更改的代码部分。
输入只有 128 字节的数组。
嵌入消息
private void openImage() {
File f = new File("C:/TEMP/CROP.png");
try {
sourceImage = ImageIO.read(f);
sourceImage = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = sourceImage.createGraphics();
g.drawImage(ImageIO.read(f), 0, 0, null);
g.dispose();
this.embedMessage();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
private void embedInteger(BufferedImage img, int n, int start) {
int maxX = img.getWidth(), maxY = img.getHeight(),
startX = start/maxY, startY = start - startX*maxY, count=0;
for(int i=startX; i<maxX && count<32; i++) {
for(int j=startY; j<maxY && count<32; j++) {
int rgb = img.getRGB(i, j);
// bit = getBitValue(n, count);
//rgb = setBitValue(rgb, 0, bit);
int bit = getBitValue(n, count); rgb = setBitValue(rgb, 0, bit);
bit = getBitValue(n, count+1); rgb = setBitValue(rgb, 8, bit);
bit = getBitValue(n, count+2); rgb = setBitValue(rgb, 16, bit);
img.setRGB(i, j, rgb);
count = count+3;
}
}
}
private void embedByte(BufferedImage img, byte b, int start) {
int maxX = img.getWidth(), maxY = img.getHeight(),
startX = start/maxY, startY = start - startX*maxY, count=0;
for(int i=startX; i<maxX && count<8; i++) {
for(int j=startY; j<maxY && count<8; j++) {
if(j==maxY-1) {
startY = 0;
}
int rgb = img.getRGB(i, j);
//bit = getBitValue(b, count);
// rgb = setBitValue(rgb, 0, bit);
int bit = getBitValue(b, count); rgb = setBitValue(rgb, 0, bit);
bit = getBitValue(b, count+1); rgb = setBitValue(rgb, 8, bit);
bit = getBitValue(b, count+2); rgb = setBitValue(rgb, 16, bit);
img.setRGB(i, j, rgb);
count = count+3;
}
}
}
解码消息
private void openImage() throws Exception {
File f = new File("C:/TEMP/Four Area/Crop image/chest-CROP2.png");
//File f = new File("C:/TEMP/chest2.png");
try {
image = ImageIO.read(f);
image = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.drawImage(ImageIO.read(f), 0, 0, null);
g.dispose();
this.decodeMessage();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private int extractInteger(BufferedImage img, int start) {
int maxX = img.getWidth(), maxY = img.getHeight(),
startX = start/maxY, startY = start - startX*maxY, count=0;
int length = 0;
for(int i=startX; i<maxX && count<32; i++) {
for(int j=startY; j<maxY && count<32; j++) {
int rgb = img.getRGB(i, j);
//bit = getBitValue(rgb, 0);
//length = setBitValue(length, count, bit);
int bit = getBitValue(rgb, 0); length = setBitValue(length, count, bit);
bit = getBitValue(rgb, 8); length = setBitValue(length, count+1, bit);
bit = getBitValue(rgb, 16); length = setBitValue(length, count+2, bit);
count = count+3;
}
}
return length;
}
private byte extractByte(BufferedImage img, int start) {
int maxX = img.getWidth(), maxY = img.getHeight(),
startX = start/maxY, startY = start - startX*maxY, count=0;
byte b = 0;
for(int i=startX; i<maxX && count<8; i++) {
for(int j=startY; j<maxY && count<8; j++) {
if(j==maxY-1) {
startY = 0;
}
int rgb = img.getRGB(i, j);
//bit = getBitValue(rgb, 0);
//b = (byte)setBitValue(b, count, bit);
int bit = getBitValue(rgb, 0); b = (byte)setBitValue(b, count, bit);
bit = getBitValue(rgb, 8); b = (byte)setBitValue(b, count+1, bit);
bit = getBitValue(rgb, 16); b = (byte)setBitValue(b, count+2, bit);
count = count+3;
}
}
return b;
}
【问题讨论】:
标签: java embed rgb decode steganography