# How to get bits from jpg image

**URL:** <https://discourse.processing.org/t/how-to-get-bits-from-jpg-image/35574>\
**Category:** Coding Questions\
**Created:** [March 5, 2022, 4:41pm UTC](https://discourse.processing.org/t/how-to-get-bits-from-jpg-image/35574 "2022-03-05T16:41:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![0ldBergamot](https://avatars.discourse-cdn.com/v4/letter/0/f05b48/32.png) [@0ldBergamot](https://discourse.processing.org/u/0ldBergamot)\
**Post date:** [March 5, 2022, 4:41pm UTC](https://discourse.processing.org/t/how-to-get-bits-from-jpg-image/35574/1 "2022-03-05T16:41:09Z")

</div>

Context :

I coded an image generator. You choose a String as input, every char is converted into its binary ascii value and each bit represents a pixel (0 = white, 1 = black). The result is save as “image.jpg”

Question :

Now I’m coding the image decoder(in order to get a string from the image), but I have no idea of how I could get the array of bits back.  
The first thing I did was to create an array of int and assign to it the value of image.pixels  
But I can’t make sense of the result.

Any idea what to do?

---

<div class="post-metadata">

**Author:** ![0ldBergamot](https://avatars.discourse-cdn.com/v4/letter/0/f05b48/32.png) [@0ldBergamot](https://discourse.processing.org/u/0ldBergamot)\
**Post date:** [March 5, 2022, 5:27pm UTC](https://discourse.processing.org/t/how-to-get-bits-from-jpg-image/35574/2 "2022-03-05T17:27:34Z")

</div>

I just realised that jpg is not a lossless format, therefore what I want to achieve may be impossible

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 5, 2022, 5:32pm UTC](https://discourse.processing.org/t/how-to-get-bits-from-jpg-image/35574/3 "2022-03-05T17:32:34Z")

</div>

The idea is valid.

Just use pixels to receive your ascii binaries and then vice versa.

Or use bmp

---

<div class="post-metadata">

**Author:** ![0ldBergamot](https://avatars.discourse-cdn.com/v4/letter/0/f05b48/32.png) [@0ldBergamot](https://discourse.processing.org/u/0ldBergamot)\
**Post date:** [March 6, 2022, 3:04pm UTC](https://discourse.processing.org/t/how-to-get-bits-from-jpg-image/35574/4 "2022-03-06T15:04:20Z")

</div>

Thank you, it worked perfectly

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 6, 2022, 11:19pm UTC](https://discourse.processing.org/t/how-to-get-bits-from-jpg-image/35574/5 "2022-03-06T23:19:03Z")

</div>

Hello @0ldBergamot,

> [@0ldBergamot](#):
>
> I just realised that jpg is not a lossless format

There are other lossless formats available to you.

Take a look at the _advanced_ section here:  
[https://processing.github.io/processing-javadocs/core/processing/core/PImage.html](https://processing.github.io/processing-javadocs/core/processing/core/PImage.html)

Try this:

```auto
printArray(javax.imageio.ImageIO.getReaderFormatNames());

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/dbf4b74ac9b46e508072ea9f81a798a85509b73f.png)

_println()_ also prints a line of formats but gives an error message.

`:)`
