# Writing 8-bit tiff images?

**URL:** https://discourse.processing.org/t/writing-8-bit-tiff-images/726
**Category:** Project Guidance
**Created:** [June 5, 2018, 3:23pm UTC](https://discourse.processing.org/t/writing-8-bit-tiff-images/726 "2018-06-05T15:23:06Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![tmhoog](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@tmhoog](https://discourse.processing.org/u/tmhoog)
#### Post date: [June 5, 2018, 3:23pm UTC](https://discourse.processing.org/t/writing-8-bit-tiff-images/726/1 "2018-06-05T15:23:06Z")

</div>

Hi, we are using Processing to acquire data and write a video stream to disk. However, we are unable to figure out how to write one-channel 8-bit **grayscale** tiff images instead of the standard RGB images. Does anyone have some pointers on how to do this? Thank you.

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [June 6, 2018, 7:54pm UTC](https://discourse.processing.org/t/writing-8-bit-tiff-images/726/2 "2018-06-06T19:54:27Z")

</div>

@tmhoog

Look at :

- [https://processing.org/discourse/beta/num\_1223399852.html](https://processing.org/discourse/beta/num_1223399852.html)

---

<div class="post-metadata">

### Author: ![tmhoog](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@tmhoog](https://discourse.processing.org/u/tmhoog)
#### Post date: [June 7, 2018, 7:46am UTC](https://discourse.processing.org/t/writing-8-bit-tiff-images/726/3 "2018-06-07T07:46:49Z")

</div>

Thanks for the pointer. We want to write only a single channel 8-bit grayscale image. My understanding reading the forum so far is that we need to write a custom function for this.

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [June 7, 2018, 12:35pm UTC](https://discourse.processing.org/t/writing-8-bit-tiff-images/726/4 "2018-06-07T12:35:50Z")

</div>

> [@tmhoog](#):
>
> My understanding reading the forum so far is that we need to write a custom function for this.

Yes, I think there’s not a built-in function in Processing for converting an image in 8-bit colors.

---

<div class="post-metadata">

### Author: ![Bird](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bird/32/118_2.png) [@Bird](https://discourse.processing.org/u/Bird)
#### Post date: [June 7, 2018, 1:19pm UTC](https://discourse.processing.org/t/writing-8-bit-tiff-images/726/5 "2018-06-07T13:19:45Z")

</div>

This is a hack function, but it works:

```auto
void convertAndSave8bitGray(PImage img) {
  Image iimg = img.getImage();
  BufferedImage bimage = new BufferedImage(iimg.getWidth(null), iimg.getHeight(null), BufferedImage.TYPE_INT_ARGB);
  Graphics2D bGr = bimage.createGraphics();
  bGr.drawImage(iimg, 0, 0, null);
  bGr.dispose();
  BufferedImage src = bimage;
  BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
  ColorConvertOp cco = new ColorConvertOp(src.getColorModel()
    .getColorSpace(), dest.getColorModel().getColorSpace(), null);
  cco.filter(src, dest);
  File outputfile = new File(sketchPath("test2.jpg"));
  try {
    ImageIO.write(dest, "jpg", outputfile);
  } 
  catch(IOException e) {
  }
}

```

---

<div class="post-metadata">

### Author: ![tmhoog](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@tmhoog](https://discourse.processing.org/u/tmhoog)
#### Post date: [June 7, 2018, 8:47pm UTC](https://discourse.processing.org/t/writing-8-bit-tiff-images/726/6 "2018-06-07T20:47:51Z")

</div>

That’s great. Thanks so much.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [June 9, 2018, 2:22pm UTC](https://discourse.processing.org/t/writing-8-bit-tiff-images/726/7 "2018-06-09T14:22:04Z")

</div>

For beginners looking to retrieve grayscale data or create grayscale images more generally (not 8-bit tiff specifically), there are also the HSB color functions – `saturation()` and `brightness()`, which return single values. Brightness in particular will return a single greyscale value for each pixel on the canvas or on a PImage / PGraphics, and you can use this as a simple built-in way to loop over pixels[] and either convert to grayscale or create a grayscale copy that can then be saved to disk.

[https://processing.org/reference/brightness\_.html](https://processing.org/reference/brightness_.html)

You can also set `colorMode(HSB)` to hue-saturation-brightness and then use `tint()` to remove the saturation on display, creating a grayscale image – although I believe it will still save as grayscale data in RGB if using the default saveFrame / saveImage.

[https://processing.org/reference/tint\_.html](https://processing.org/reference/tint_.html)
