简体   繁体   English

如何根据我的信息更改每个像素的LSB

[英]How do I change the LSB of each pixel according to my message

I am trying to implement a simple encoding program where I can hide a message in the LSB of the pixels of an image. 我正在尝试实现一个简单的编码程序,在该程序中我可以在图像像素的LSB中隐藏一条消息。 So far I've got the byte array from the message 到目前为止,我已经从消息中获得了字节数组

    private static byte[] ConvertMessageToByte(String message,
        byte[] messageBytes) {
    // takes in the message and stores them into bytes
    // returns message byte array
    byte[] messageByteArray = message.getBytes();

    return messageByteArray;

}

I have also got the byte array for the corresponding image that i want to encode onto 我也有要编码到的对应图像的字节数组

    private static byte[] getPixelByteArray(BufferedImage bufferedImage) {

    WritableRaster raster = bufferedImage.getRaster();

    DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();

    return buffer.getData();

}

Till this point I don't quite understand my following steps after. 到目前为止,我还不太了解接下来的步骤。 Do I iterate through the image byte array and store each ARGB values in another byte array? 是否要遍历图像字节数组并将每个ARGB值存储在另一个字节数组中? Also how would I apply the message bit values to the pixels? 另外,如何将消息位值应用于像素?

private static byte[] ConvertMessageToByte(String message, byte[] messageBytes) {
    byte[] messageByteArray = message.getBytes();
    return messageByteArray;
}

Regarding this method: convertMessageToBytes is a better name as a lowercase first letter is more conventional as well as the fact that you are producing an array of multiple bytes and not just one. 关于此方法: convertMessageToBytes是一个更好的名称,因为小写的首字母更为常规,而且您生成的是多个字节的数组,而不仅仅是一个字节。 This method does not require the second byte[] parameter as it can be simplified to return message.getBytes(); 此方法不需要第二个byte[]参数,因为它可以简化为return message.getBytes(); and produce the same effect. 并产生相同的效果。 Furthermore, String.getBytes() is typically called in the parent function of this as it is not widely considered worthy of wrapping given that is one line. 此外,通常在此方法的父函数中调用String.getBytes() ,因为考虑到只有一行,它不被普遍认为值得包装。 In conclusion: remove this method and use byte[] ba = s.getBytes(); 结论:删除此方法,并使用byte[] ba = s.getBytes(); in your main code instead. 在您的主代码中。

Personally, I process images as 3_BYTE_RGB as that is how they are most commonly thought of and, indeed, represented on a physical monitor or printer and stored in the case of many image formats. 就我个人而言,我将图像处理为3_BYTE_RGB因为这是人们最常想到的方式,并且实际上将其表示在物理监视器或打印机上,并以多种图像格式存储。 HSL (LSB) is typically a user-end representation of colour. HSL(LSB)通常是颜色的用户端表示。 You should be thinking in RGB not HSL. 您应该考虑使用RGB,而不是HSL。

Instead of dealing with the image as a byte[] , use int BufferedImage.getRGB(int x, int y) as it's easier to do and easier to access. 与其将图像作为byte[] ,还不如使用int BufferedImage.getRGB(int x, int y)因为这样做更容易访问。 The following function may be of use. 以下功能可能有用。 I'll let you write the reverse. 我让你写反面。

private static int[] getColourAt(BufferedImage image, int x, int, y) {
  int rgb = image.getRGB(x, y);
  int r = rgb >> 16;
  int g = (rgb >> 8) % 256;
  int b = rgb % 256;
  return new int[] {r, g, b};
}

From there, you should loop through each pixel and adjust as you like. 从那里,您应该遍历每个像素并根据需要进行调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 history() 方法面临的问题,我如何根据最旧的更改进行排序? - Problem faced with my history() method, how do I sort according to oldest change? 如何线性缩放像素着色? - How do I linearly scale my pixel coloring? 如何在Java Applet中测试像素的颜色? - How do I test for the color of a pixel in my Java Applet? 每次调用ActionListener时,如何明显更改JScrollPane的内容? - How do I visibly change the contents of my JScrollPane each time I call the ActionListener? 如何根据某些情况重复我的程序? - How do I make my program repeat according to certain circumstances? Java:如何检测格式并从图像中读取每个像素的RGB值? - Java: How do I detect the format and read the RGB values of each pixel from an image? 我第一次访问“活动”时,“片段”中的菜单项不会根据代码更改 - Menuitems in my Fragments do not change according to the code for the first time I access Activity 如何为实时数据库中的每条消息生成唯一密钥? - How do I generate a unique key for each message in Realtime Database? 如何将我的信息连接到我的吐司消息 - How do I connect my information to my toast message 骆驼Cxf:如何更改传入消息的名称空间? - Camel Cxf: How can I change the namespace of my incoming message?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM