Note that there are some explanatory texts on larger screens.

plurals
  1. POPNG File format and Image bytes?
    primarykey
    data
    text
    <p>I am currently trying to write a program to encode text into a png file only changing the least significant bit for each letter i want to encode in the picture, example I have a 'A' which is 65 and I use 8 different bytes to encode the letter A. So 01010100&lt;- 10101101&lt;- 11011010&lt;- 10101010&lt;- each of these I change the last bit and the put 10110110&lt;- 01010100&lt;- 01010100&lt;- 01010101&lt;- them together so 65 is 01000001 each number by the arrow is changed according to the 65.</p> <p>If I should approach this a different way suggestions would be awesome :). This is just a fun little project I wanted to do. But anyways back to my question.</p> <p>When I read in a image that is only 4 pixels big I get like 680 bytes which is crazy, or at least I think it is, maybe im wrong? 4 pixels with ARGB at 8 bits each should be 16 bytes with a few bytes im sure to tell the operating system that it is a png and how to handle it. So i was expecting maybe like 30 bytes. Maybe less. Am I looking at this the wrong way? When png images are compressed do they become bigger if it is a small picture? And also, when I was saving it back to the Hard drive I always got a larger file. The original picture was 8,554 kb and then it turned into like 16kb when I saved it back. Here is the code for getting the image bytes and for saving the image. Maybe I am doing something wrong or I am just not understanding it correctly.</p> <p>These are the ways I get the image (I tried 2 different things)</p> <blockquote> <p>// BufferedImage img = ImageIO.read(new File("image.png"));<br> BufferedImage img= robot.createScreenCapture(new Rectangle(1,2,2,2));</p> </blockquote> <p>how I saved two different ways again.</p> <blockquote> <p>try {<br> InputStream in = new ByteArrayInputStream(imgBytes); <br> BufferedImage bImageFromConvert = ImageIO.read(in); <br> ImageIO.write(bImageFromConvert, "png", new File( "image.png"));<br> <br> //FileOutputStream fos = new FileOutputStream("image.png");<br> //fos.write(b);<br> //fos.close();<br> }catch(Exception e){}<br></p> </blockquote> <p>How I got the bytes from the Image, again I tried two different ways, the second way that is commented out actually did give me the 16 bytes like I want but when I saved it the Windows couldnt Open it because it didnt know what it was i guess? Not sure, just said file not supported.</p> <blockquote> <p>byte[] imageBytes = null;<br> try{<br> ByteArrayOutputStream baos = new ByteArrayOutputStream();<br> ImageIO.write(image, "jpg", baos );<br> baos.flush();<br> imageBytes = baos.toByteArray();<br> baos.close();<br> }catch(IOException e){System.out.println(e.getMessage());}<br><br> // imageBytes = ((DataBufferByte) image.getData().getDataBuffer()).getData();<br> return imageBytes;<br></p> </blockquote> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload