Convert To BW

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Convert To BW

Post by jeffp »

I have an IIXC_Page object that is a gray scale image. I need to convert it into a black and white image.

Here is what I'm using currently

var
APage: IIXC_Page;
begin
APage.ConvertToFormat(PageFormat_1Indexed);
APage.Set_FmtInt(FP_ID_ITYPE, 1);
APage.Set_FmtInt(FP_ID_BPP, 1);

However, the last line that sets the BPP to 1 inverts the image so what was white is now black.

Is this the correct way to covert a gray scale image to black and white? If not, how would you suggest I accomplish this with the IIXC_Page object?

--Jeff
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Convert To BW

Post by Sasha - Tracker Dev Team »

Hello Jeff,

Are you using the Editor SDK or Core API?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Convert To BW

Post by jeffp »

I need to be able to make this conversion via the API in code. Again using the IIXC_Page object.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Convert To BW

Post by Sasha - Tracker Dev Team »

Hello Jeff,

Can you please give us a full sample, that does this conversion and also, that will give us the same presentation of the result that you have (to investigate the inverse part), because this code alone is not enough to make a correct judgement.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Convert To BW

Post by jeffp »

I'm having a hard time finding the sample file that wasn't working.

Can I just ask what calls you would make to turn a GrayScale or Color image into a BW image?

--Jeff
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Convert To BW

Post by Sasha - Tracker Dev Team »

Hello Jeff,

We've implemented the IIXC_Page::ReduceColorsFixedPalette method that will allow you to set the needed colors palette (in your case the Black and White colors) and make the image BW. This will be available from the next release (326).
PS: No release ETA yet.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Convert To BW

Post by jeffp »

Thanks.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Convert To BW

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Convert To BW

Post by jeffp »

Ok The call is defined as

function ReduceColorsFixedPalette(pFixedPalette: PSafeArray; nDitherMethod: IXC_DitherMethod): HResult; stdcall;

Can you help me with what to set for pFixedPallette to turn the page into a BW image

APage.ReduceColorsFixedPalette(???, Dither_none);

Also, how does ReduceColorsAdaptive compare to ReduceColorsFixedPalette?

Again, I'm using Delphi.

--Jeff
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Convert To BW

Post by Sasha - Tracker Dev Team »

Hello Jeff,

You should have something like this:

Code: Select all

static RGBQUAD bw_palette[] = {{0, 0, 0, 0}, {0xFF, 0xFF, 0xFF, 0}};
I will try to write a code sample tomorrow.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Convert To BW

Post by jeffp »

Yes. A Delphi Code sample would be great. Again, lookiing for the optimal way to convert an image to black and white.

You have a APage.ToGrayscale procedure currently. Maybe you should add APage.ToBW

Thanks again.

--Jeff
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Convert To BW

Post by Sasha - Tracker Dev Team »

Hello Jeff,

I've update a description of this method here:
https://sdkhelp.pdf-xchange.com/vi ... xedPalette
And also, I've made a working sample (4.12. ChangeAllOfTheImagesToBlackAndWhite) in the CoreAPIDemo project available from here:
https://github.com/tracker-software/PDFCoreSDKExamples

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply