Skip to main content
wckdtall
Inspiring
November 7, 2014
Answered

Is there a simple way to convert bit depth to 16 bit?

  • November 7, 2014
  • 1 reply
  • 910 views

It seems there are PDF/BITMAP specific methods to convert to 8 bit depth, but I can't find any documentation to do this easily to the file as a whole. Is there a way to do this? I want to convert from 32 to 16 bit.

This topic has been closed for replies.
Correct answer xbytor2

I have code in Image Processor Pro that looks like this:

  // Bit Depth

  var bd = toNumber(task.@bitDepth) || 0;

  if (bd) {

    var bpc = doc.bitsPerChannel;

    try {

      if (bd == 8) {

        doc.bitsPerChannel = BitsPerChannelType.ONE;

      } else if (bd == 8) {

        doc.bitsPerChannel = BitsPerChannelType.EIGHT;

      } else if (bd == 16) {

        doc.bitsPerChannel = BitsPerChannelType.SIXTEEN;

      } else if (bd == 32) {

        doc.bitsPerChannel = BitsPerChannelType.THIRTYTWO;

      }

    } catch (e) {

      LogFile.logException(e, "Error selecting bit depth " + bd);

    }

  }

Then, later, I have this code which changes the document mode so that you can save it as a bmp file:

  if (ImageProcessorOptions.JDI && ext == "bmp") {
    // We need to make adjustments depending the number of
    // bmp save bits selected
    if (saveOpts.depth == BMPDepthType.ONE ||
        saveOpts.depth == BMPDepthType.SIXTEEN ||
        saveOpts.depth == BMPDepthType.TWENTYFOUR ||
        saveOpts.depth == BMPDepthType.THIRTYTWO) {
      saveOpts.rleCompression = false;
    }

    if (saveOpts.depth == BMPDepthType.FOUR ||
        saveOpts.depth == BMPDepthType.EIGHT) {
      doc.changeMode(ChangeMode.GRAYSCALE);
    }

    if (saveOpts.depth == BMPDepthType.ONE) {
      if (doc.mode != ChangeMode.BITMAP) {
        doc.changeMode(ChangeMode.GRAYSCALE);
      }
      var cnvtOpts = new BitmapConversionOptions();
      doc.changeMode(ChangeMode.BITMAP, cnvtOpts);
    }
  }

I don't think I've tested with pdfs files.

Hope this helps.

1 reply

xbytor2Correct answer
Inspiring
November 8, 2014

I have code in Image Processor Pro that looks like this:

  // Bit Depth

  var bd = toNumber(task.@bitDepth) || 0;

  if (bd) {

    var bpc = doc.bitsPerChannel;

    try {

      if (bd == 8) {

        doc.bitsPerChannel = BitsPerChannelType.ONE;

      } else if (bd == 8) {

        doc.bitsPerChannel = BitsPerChannelType.EIGHT;

      } else if (bd == 16) {

        doc.bitsPerChannel = BitsPerChannelType.SIXTEEN;

      } else if (bd == 32) {

        doc.bitsPerChannel = BitsPerChannelType.THIRTYTWO;

      }

    } catch (e) {

      LogFile.logException(e, "Error selecting bit depth " + bd);

    }

  }

Then, later, I have this code which changes the document mode so that you can save it as a bmp file:

  if (ImageProcessorOptions.JDI && ext == "bmp") {
    // We need to make adjustments depending the number of
    // bmp save bits selected
    if (saveOpts.depth == BMPDepthType.ONE ||
        saveOpts.depth == BMPDepthType.SIXTEEN ||
        saveOpts.depth == BMPDepthType.TWENTYFOUR ||
        saveOpts.depth == BMPDepthType.THIRTYTWO) {
      saveOpts.rleCompression = false;
    }

    if (saveOpts.depth == BMPDepthType.FOUR ||
        saveOpts.depth == BMPDepthType.EIGHT) {
      doc.changeMode(ChangeMode.GRAYSCALE);
    }

    if (saveOpts.depth == BMPDepthType.ONE) {
      if (doc.mode != ChangeMode.BITMAP) {
        doc.changeMode(ChangeMode.GRAYSCALE);
      }
      var cnvtOpts = new BitmapConversionOptions();
      doc.changeMode(ChangeMode.BITMAP, cnvtOpts);
    }
  }

I don't think I've tested with pdfs files.

Hope this helps.

wckdtall
wckdtallAuthor
Inspiring
November 8, 2014

Thanks! I'm just working with Tifs, but I mentioned pdf, cause there's code on the save side to convert bit depth. As per usual, I probably had my syntax wrong, but his is exactly the method I was looking for! Thanks!