问题
I found a tutorial from this website Steganography (it also include the code), and i want to put the four message into four difference part of image as i drew below link Four parties of image, but i am not sure how to exactly to put message to four of section. This is one part of the code i modified by using raster below
private byte[] get_byte_data(BufferedImage image) {
WritableRaster raster = image.getRaster();
int imageHeight=image.getHeight()/2;
System.out.println("ImageHeight: "+imageHeight);
int imageWidth=image.getWidth()/2;
System.out.println("ImageWidth: "+imageWidth);
DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();
return buffer.getData();
}
How can i put the message into the exactly section i wanted?
回答1:
I will offer my answer from a previous related question of yours.
There I showed you how you can hide a different message in each R, G, B and A component of an image, which conveniently is 4. To use it, embed the first message in R and save the output. Then load that output and store the next message in G and resave the output. And so on... Since each message makes uses of each colour component, each message can have a maximum size of (p - 32)/8.
Pros: it effectively achieves what you want, the code is already there for you, maximum capacity possible.
Cons: it's very slightly cumbersome to use due to the loading -> embedding -> saving x4 aspect.
Now, if you are really adamant and you want to actually split the image in 4 parts, you have to apply the following changes in the code (from the previous question, but start with the original as offered in the website):
- Change the GUI so it has 4 text boxes.
- After loading the complete image, pass on only a quarter of it in the
embedMessage
method. The four quadrants should have coordinates (0:maxX/2, 0:maxY/2), (0:maxX/2, maxY/2:maxY), (maxX/2:maxX, 0:maxY/2) and (maxX/2:maxX, maxY/2:maxY), wheremaxX = yourimage.getWidth()
andmaxY = yourimage.getHeight()
. You can do this with thegetSubimage
method on your image data.
The problem is that for each quadrant, you're still embedding in one colour component, so effectively each message cannot be longer than (p/4 - 32)/8, which is almost 4 times less the capacity than my suggested method.
You can achieve maximum capacity as above by embedding in all R, G, B and A components for each quadrant. This is also something that I showed you how to do in my linked answer.
All of this will require some code modification, but I have provided you all the concepts and logic structure for the changes you want to make.
Pros: it's convenient to use with 4 text message boxes.
Cons: it will take effort to code the modifications for the same maximum capacity compared to the other suggestion above.
回答2:
Concept of Steganography and Java image manipulation should be understood separately. In Steganography we are embedding bytes of hidden message to bytes of carrier message. In a byte array of carrier we cannot identify where each of these image sections begin as for your requirement.
So what you have to do is this. First split up carrier image to four separate images, then append the bytes as required with the hidden data bytes. Then create new image object and draw these four separated images on that in correct locations.
来源:https://stackoverflow.com/questions/21127860/put-invisible-message-in-four-part-of-image-by-using-raster