split multipage image into single images

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's Image-XChange Imaging SDK (only).

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software, Tracker - Clarion Support, John - Tracker Supp, Support Staff, moderators

Post Reply
twinklekumarp
User
Posts: 17
Joined: Thu Dec 08, 2005 7:57 am
Location: Bangalore
Contact:

split multipage image into single images

Post by twinklekumarp » Thu Dec 08, 2005 8:04 am

Hi All,

I m new to this SDK and i want one quick help. My proglem is with spliting and image. I have one multipage image and i want to split or cut down these image in to single page images. Means if multipage image has three pages then the out put should be three single page images numberd 1,2 and 3 with proper format extension.

Do any one has idea which functions we have to use from ImageXchange SDK and how to implement these functions in VC++ project in .net

In short i want to create one STDMETHOD in that project using which i can do my job. The input paratmeter will be file name of the image.
Attachments

[The extension tif has been deactivated and can no longer be displayed.]

Hi, I m twinkle patel and working on .net platform and want to work on image processing.

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Thu Dec 08, 2005 10:26 am

Hi,

Please see the Pseudo code below - which should be good pretty much for any .NET environment.

(C++, without error handling):

1. Load image, retreiving it's handle
IXCImg hImage = IMG_ImageLoad(...);
int pages_count;
IMG_ImageGetPagesCount(hImage, pages_count);

2. Step through the file for all pages and copy the page into temp image and do save (only image can be saved) Also you have the ability to set a different file format (Just call func IMG_PageSetFormatLongParameter with the appropriate arguments)
for (int i = 0; i < pages_count; i++) {
XCImage img;
XCPage page;
IMG_ImageGetPage(hImage, i, &page);
IMG_ImageCreateEmpty(&img);
IMG_ImageInsertPageCopy(hImage, img, page);
// here is setting save parameters
IMG_PageSetFormatLongParameter(vPages[k], FP_ID_FORMAT, fmt_id/*FMT_BMP_ID*/);
IMG_PageSetFormatLongParameter(vPages[k], FP_ID_ITYPE, type/*ImageFormat_RGB_8*/);
IMG_ImageSaveToFile(img, fname_tosave, action);
IMG_ImageDestroy(img);
}
IMG_ImageDestroy(hImage);
++++++++++++++++++++
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

twinklekumarp
User
Posts: 17
Joined: Thu Dec 08, 2005 7:57 am
Location: Bangalore
Contact:

Post by twinklekumarp » Thu Dec 08, 2005 3:08 pm

Hi Thanks for the code but my type of code is like this type so i want in this coding style

HRESULT CPDFToolServices::ObtainImageInformation(LPCTSTR szImageFile, int & riImageCount, bool & rbGrayScale)
{
m_oLog.Debug("ObtainImageInformation called for file '%s'.", szImageFile);

CHResultT hRT;
IMAGE_HANDLER hImageList = NULL;
HRESULT hr = S_OK;

try
{
// Pre-set in case of error below...
riImageCount = 0;
rbGrayScale = false;

// Open the file to get the information out of it.
hRT = hImageList = IMG_AddImageFromFile(szImageFile, NULL, 0);
m_oLog.Debug("hRT Value is %d", hRT);

hRT = riImageCount = IMG_GetPagesCount(hImageList);

rbGrayScale = IMG_IsImageGrayscale(hImageList, 0) ? true : false;

hr = IMG_RemovePage(hImageList, 0);
hr = IMG_CloseImageFile(hImageList);

hImageList = NULL;
}
catch (_com_error & rException)
{
_ASSERTE(false && "ObtainImageInformation encountered an unexpected COM error.");
m_oLog.Error(CreateAndSetCOMInfo(_T("ObtainImageInformation"), rException.Error(), rException.ErrorMessage()));

if (hImageList)
{
// Release all image handles in memory
IMG_RemovePage(hImageList, 0);
IMG_CloseImageFile(hImageList);
hImageList = NULL;
}
}

return hRT;
}


so how to write in similar way usign this language

thanks
Hi, I m twinkle patel and working on .net platform and want to work on image processing.

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Thu Dec 08, 2005 3:35 pm

I am sorry - I am not sure I fully understand.

Although it does seem you are testing Version 1 of Image-Xchange perhaps which is very old now - please visit our web site and download the latest V3.5 release :

http://www.tracker-software.com/downloads/dev/

The Pseudo code supplied is VC++ - which as I understand you are familiar with and you should be able to adapt as you require ?
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

twinklekumarp
User
Posts: 17
Joined: Thu Dec 08, 2005 7:57 am
Location: Bangalore
Contact:

Post by twinklekumarp » Sun Dec 11, 2005 10:31 am

HI, Thanks for the code

but in my SDK I don't have any functions like


IMG_ImageGetPage(hImage, i, &page);
IMG_ImageCreateEmpty(&img);
IMG_ImageInsertPageCopy(hImage, img, page);
// here is setting save parameters
IMG_PageSetFormatLongParameter(vPages[k], FP_ID_FORMAT, fmt_id/*FMT_BMP_ID*/);
IMG_PageSetFormatLongParameter(vPages[k], FP_ID_ITYPE, type/*ImageFormat_RGB_8*/);
IMG_ImageSaveToFile(img, fname_tosave, action);
IMG_ImageDestroy(img);

Here i m attaching the .chm file which i have
Can u suggest me which functions from this help file i have to use in order to split the image.

i m really confused between page and image

and how to declare XCPage page in vc++

thanks,
Twinkle
Attachments
ImageXChangeHelp.zip
(151.33 KiB) Downloaded 269 times
Hi, I m twinkle patel and working on .net platform and want to work on image processing.

twinklekumarp
User
Posts: 17
Joined: Thu Dec 08, 2005 7:57 am
Location: Bangalore
Contact:

Post by twinklekumarp » Mon Dec 12, 2005 10:37 am

Hi, In order to split the image file i have write this function

But it creates 0 kb file.

Can u suggest what is wrong with my code..

STDMETHODIMP CPDFToolServices::SplitMultiPageImage(BSTR bsImageFile,VARIANT_BOOL vbSplitPages,LONG* plNumberFilesCreated)
{
// Reset the error indicator -- entry point into this library
m_bErrorSet = false;

CString sImageFile;

bool bSplitPages = vbSplitPages == VARIANT_TRUE;
long lStartingFileNumber = bSplitPages ? 1 : 0;

sImageFile = bsImageFile;

m_oLog.Debug("SplitMultiPageImage(%s, %d)", SafeStringPointer(sImageFile), bSplitPages);

//-----
// Validate all of the passed information. I will exit early if I find badness!
//
if (! PathFileExists(sImageFile) || PathIsDirectory(sImageFile))
{
_ASSERTE(false && "Image file does not exist to process or is a directory in which case it still does not exist.");
m_oLog.Error(CreateAndSetCOMInfo(_T("SplitMultiPageImage"), E_UNEXPECTED, _T("Image file does not exist to process or is a directory in which case it still does not exist.")));
return E_INVALIDARG;
}

if (plNumberFilesCreated == NULL)
{
_ASSERTE(false && "plNumberFilesCreated must not be NULL.");
m_oLog.Error(CreateAndSetCOMInfo(_T("SplitMultiPageImage"), E_UNEXPECTED, _T("plNumberFilesCreated must not be NULL.")));
return E_INVALIDARG;
}
//-------

CHResultT hRT;
HRESULT hr;
CString sFileName;

int iImageCount = 0;

IMAGE_HANDLER hImageList = NULL;
DWORD hImage = NULL;
DWORD xDPI = 0;
DWORD yDPI = 0;
DWORD AppMode = 1;
DWORD frm = 0;

try
{

// Open the file to get the information out of it.
hImageList = IMG_AddImageFromFile(sImageFile, NULL, 0);


hRT = iImageCount = IMG_GetPagesCount(hImageList);


// Now process the images that we just got

for (int i = 0; i < iImageCount; i++)
{
sFileName = CreateImageFileName(_T("C:\\"), lStartingFileNumber );
lStartingFileNumber += 1;
hr = IMG_AppendPageToFile(hImageList,i,sFileName ,AppMode );

}

}
catch (_com_error & rException)
{
_ASSERTE(false && "SplitMultiPageImage encountered an unexpected COM error.");
m_oLog.Error(CreateAndSetCOMInfo(_T("SplitMultiPageImage"), rException.Error(), rException.ErrorMessage()));
}

// Release any resources captured above.
if (hImageList != NULL)
{
IMG_CloseImageFile(hImageList);
IMG_RemoveImage(hImageList);
hImageList = NULL;
}

return hRT;
}
Hi, I m twinkle patel and working on .net platform and want to work on image processing.

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Mon Dec 12, 2005 4:14 pm

Hi - You seem to be confusing code for differing versions - may I suggest we start at the very beginning doing the following :

1: Please uninstall all you have from your PC regarding Image-XChange

2: Download and install the latest Version 3 release and install

http://www.tracker-software.com/download/IMX3SDK.zip

3: Then - using the PSEUDO code below - create your application as required - your code above is for Version 1 and will not function correctly/reliabley.

++++++++++++++++++++++

(C++, without error handling):

1. Load image, retreiving it's handle
IXCImg hImage = IMG_ImageLoad(...);
int pages_count;
IMG_ImageGetPagesCount(hImage, pages_count);

2. Step through the file for all pages and copy the page into temp image and do save (only image can be saved) Also you have the ability to set a different file format (Just call func IMG_PageSetFormatLongParameter with the appropriate arguments)
for (int i = 0; i < pages_count; i++) {
XCImage img;
XCPage page;
IMG_ImageGetPage(hImage, i, &page);
IMG_ImageCreateEmpty(&img);
IMG_ImageInsertPageCopy(hImage, img, page);
// here is setting save parameters
IMG_PageSetFormatLongParameter(vPages[k], FP_ID_FORMAT, fmt_id/*FMT_BMP_ID*/);
IMG_PageSetFormatLongParameter(vPages[k], FP_ID_ITYPE, type/*ImageFormat_RGB_8*/);
IMG_ImageSaveToFile(img, fname_tosave, action);
IMG_ImageDestroy(img);
}
IMG_ImageDestroy(hImage);
++++++++++++++++++++
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

twinklekumarp
User
Posts: 17
Joined: Thu Dec 08, 2005 7:57 am
Location: Bangalore
Contact:

Post by twinklekumarp » Tue Dec 13, 2005 4:52 am

Hi,

Thanks for the point out about the version.

But we have licensed version of ur product and we have already incorporated that version for our product if we change the version we need to recoding the whole code for our dll becoz the function names are changed.

So please let me know is that possible in version which i specified and if u want any more information regarding the SDK i m using then please told me

i have installed this version : PDFSDK25.exe



thanks,
Twinkle
Hi, I m twinkle patel and working on .net platform and want to work on image processing.

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Tue Dec 13, 2005 11:05 am

Hi,

If you have licensed PDFSDK25.exe - this is PDF-XChange for creating PDF Files and neither your code or that provided is relevant to converting multipage Image files to single page Image files ????

You are asking questions in the Image-XChange Forum ?

Can I suggest you send your purchase info to :

mailto:upgrades@tracker-software.com

we can then see which products you have licensed and then advise you accordingly.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

twinklekumarp
User
Posts: 17
Joined: Thu Dec 08, 2005 7:57 am
Location: Bangalore
Contact:

Post by twinklekumarp » Tue Dec 13, 2005 11:41 am

Hi ,

Sorry i have given wrong SDK name

it is : ImageXChangeSDK.exe

thanks,
Twinkle
Hi, I m twinkle patel and working on .net platform and want to work on image processing.

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Tue Dec 13, 2005 11:44 pm

Ok - here is an example in C++ and V1 of Image-XChange which should allow you to progress as required:

IMAGE_HANDLER multipage = NULL;
HRESULT hr;
do
{
// use add image to prevent whoule image to be immediately loaded
multipage = IMG_AddImageFromFile("test.tif", NULL, 0);
if (IS_IMG_ERROR(multipage))
break;
hr = IMG_GetPagesCount(multipage);
if (IS_IMG_ERROR(hr))
break;
int pagesCount = hr;
char destName[MAX_PATH];
destName[0] = '\0';
for (int i = 0; i < pagesCount; i++)
{
// generate file name
sprintf(destname, "page%d.tif", i);
// save page into file and remove it later to free memory, so next time we should againg write first page
hr = IMG_AppendPageToFile(multipage, 0, destName, DI_ACTION_OWERWRITE);
if (IS_IMG_ERROR(hr))
break;
// page saved, remove it here to free memory
// if you don't want to remove pages from image (not image file!) change page index in previous call
// from '0' to 'i', but in such case after splitting all pages you will have all pages readed into memory
hr = IMG_RemovePage(multipage, 0);
if (IS_IMG_ERROR(hr))
break;
}
}
while (FALSE);
if ((multipage != NULL) && (!IS_IMG_ERROR(multipage)))
IMG_RemoveImage(multipage);
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

twinklekumarp
User
Posts: 17
Joined: Thu Dec 08, 2005 7:57 am
Location: Bangalore
Contact:

Post by twinklekumarp » Wed Dec 14, 2005 10:04 am

Hi,

Thanks for the code.

I have done the same thing but it is creating zero (0) kb file on my hard disk. I don't know what is going wrong. Here is the function which i have written for that purpose.

STDMETHODIMP CPDFToolServices::SplitMultiPageImage(BSTR bsImageFile,VARIANT_BOOL vbSplitPages,LONG* plNumberFilesCreated)
{
// Reset the error indicator -- entry point into this library
m_bErrorSet = false;

CString sImageFile;

bool bSplitPages = vbSplitPages == VARIANT_TRUE;
long lStartingFileNumber = bSplitPages ? 1 : 0;

sImageFile = bsImageFile;

m_oLog.Debug("SplitMultiPageImage(%s, %d)", SafeStringPointer(sImageFile), bSplitPages);

//-----
// Validate all of the passed information. I will exit early if I find badness!
//
if (! PathFileExists(sImageFile) || PathIsDirectory(sImageFile))
{
_ASSERTE(false && "Image file does not exist to process or is a directory in which case it still does not exist.");
m_oLog.Error(CreateAndSetCOMInfo(_T("SplitMultiPageImage"), E_UNEXPECTED, _T("Image file does not exist to process or is a directory in which case it still does not exist.")));
return E_INVALIDARG;
}

if (plNumberFilesCreated == NULL)
{
_ASSERTE(false && "plNumberFilesCreated must not be NULL.");
m_oLog.Error(CreateAndSetCOMInfo(_T("SplitMultiPageImage"), E_UNEXPECTED, _T("plNumberFilesCreated must not be NULL.")));
return E_INVALIDARG;
}
//-------

CHResultT hRT;
HRESULT hr;
CString sFileName;

int iImageCount = 0;

IMAGE_HANDLER hImageList = NULL;
DWORD hImage = NULL;
DWORD xDPI = 0;
DWORD yDPI = 0;
DWORD AppMode = 1;
DWORD frm = 0;

try
{

// Open the file to get the information out of it.
hImageList = IMG_AddImageFromFile(sImageFile, NULL, 0);


hRT = iImageCount = IMG_GetPagesCount(hImageList);


// Now process the images that we just got

for (int i = 0; i < iImageCount; i++)
{
sFileName = CreateImageFileName(_T("C:\\"), lStartingFileNumber );
lStartingFileNumber += 1;
hr = IMG_AppendPageToFile(hImageList,i,sFileName ,AppMode );

}

}
catch (_com_error & rException)
{
_ASSERTE(false && "SplitMultiPageImage encountered an unexpected COM error.");
m_oLog.Error(CreateAndSetCOMInfo(_T("SplitMultiPageImage"), rException.Error(), rException.ErrorMessage()));
}

// Release any resources captured above.
if (hImageList != NULL)
{
IMG_CloseImageFile(hImageList);
IMG_RemoveImage(hImageList);
hImageList = NULL;
}

return hRT;
}


Thanks,
Twinkle
Hi, I m twinkle patel and working on .net platform and want to work on image processing.

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Wed Dec 14, 2005 10:45 am

To try and speed up a resolution to this, please do as follows,

Please provide a small sample application, both compiled and full project source - zipped!

We will test and correct if necessary and return.

thanks
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Post Reply