Copy link to clipboard
Copied
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.
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;
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!