Convert To BW

PDF-XChange Editor SDK for Developers

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

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: 854
Joined: Wed Sep 30, 2009 6:53 pm

Convert To BW

Post by jeffp » Thu Mar 29, 2018 9:12 pm

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

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

Re: Convert To BW

Post by Sasha - Tracker Dev Team » Fri Mar 30, 2018 10:11 am

Hello Jeff,

Are you using the Editor SDK or Core API?

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jeffp
User
Posts: 854
Joined: Wed Sep 30, 2009 6:53 pm

Re: Convert To BW

Post by jeffp » Fri Mar 30, 2018 12:19 pm

I need to be able to make this conversion via the API in code. Again using the IIXC_Page object.

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

Re: Convert To BW

Post by Sasha - Tracker Dev Team » Mon Apr 02, 2018 8:57 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jeffp
User
Posts: 854
Joined: Wed Sep 30, 2009 6:53 pm

Re: Convert To BW

Post by jeffp » Wed May 16, 2018 3:24 pm

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

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

Re: Convert To BW

Post by Sasha - Tracker Dev Team » Thu May 17, 2018 12:28 pm

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jeffp
User
Posts: 854
Joined: Wed Sep 30, 2009 6:53 pm

Re: Convert To BW

Post by jeffp » Thu May 17, 2018 2:13 pm

Thanks.

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

Re: Convert To BW

Post by Sasha - Tracker Dev Team » Thu May 17, 2018 2:32 pm

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jeffp
User
Posts: 854
Joined: Wed Sep 30, 2009 6:53 pm

Re: Convert To BW

Post by jeffp » Thu Jan 03, 2019 8:24 pm

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

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

Re: Convert To BW

Post by Sasha - Tracker Dev Team » Fri Jan 04, 2019 4:00 pm

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jeffp
User
Posts: 854
Joined: Wed Sep 30, 2009 6:53 pm

Re: Convert To BW

Post by jeffp » Fri Jan 04, 2019 4:15 pm

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

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

Re: Convert To BW

Post by Sasha - Tracker Dev Team » Tue Jan 08, 2019 9:54 am

Hello Jeff,

I've update a description of this method here:
https://sdkhelp.tracker-software.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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply