title: Steganography Lsb information hold capacity
body: <p>I know that using LSB means that u can store messages at around 12% of the image carrier size.
   I made a java program that splits a message into n fragments and fills the image carrier with these fragments until the 12 % are all occupied.I do this so that by cropping the image,the message wouldn't get lost.
   The problem is that the resulting image is distorted and different from the original image.I thought that if I fill only 12% of the image,more exactly the LSB of the image,the image wouldn't get distorted.</p>
  
  <pre><code>    int numHides = imLen/(totalLen*DATA_SIZE); // the number of messages I can store in the image
      int offset = 0;
      for(int h=0; h &lt; numHides; h++) //hide all frags, numHides times
      for(int i=0; i &lt; NUM_FRAGS; i++) {//NUM_FRAGS ..the number of fragments 
            hideStegoFrag(imBytes, stegoFrags[i], offset);//the method that hides the fragment into the picture starting at the offset position
            offset += stegoFrags[i].length*DATA_SIZE;
      }
  
     private static boolean hideStegoFrag(byte[] imBytes,byte[] stego,int off){
       int offset=off;
       for (int i = 0; i &lt; stego.length; i++) { // loop through stego
        int byteVal = stego[i];
        for(int j=7; j &gt;= 0; j--) { // loop through 8 bits of stego byte
           int bitVal = (byteVal &gt;&gt;&gt; j) &amp; 1;
           // change last bit of image byte to be the stego bit
           imBytes[offset] = (byte)((imBytes[offset] &amp; 0xFE) | bitVal);
           offset++;
        }
      }
      return true;
  }
  </code></pre>
  
  <p>The code for transforming the Buffered Image into bits</p>
  
  <pre><code>       private static byte[] accessBytes(BufferedImage image)
         {
          WritableRaster raster = image.getRaster();
          DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();
          return buffer.getData();
         }
  </code></pre>
  
  <p>The code that creates the new image with a provided name and the buffered image of the source image</p>
  
  <pre><code>      public static boolean writeImageToFile(String imFnm , BufferedImage im){
      try {
          ImageIO.write(im, "png", new File(imFnm));
      } catch (IOException ex) {
          Logger.getLogger(MultiSteg.class.getName()).log(Level.SEVERE, null, ex);
      }
  return true;
  </code></pre>
  
  <p>}
  <img src="https://i.stack.imgur.com/p9WuC.png" alt="original image">
  <img src="https://i.stack.imgur.com/RsCdh.png" alt="The modified image"></p>