multipage tiff file to array of regular images using ImageMagick functions
-
- Posts: 4
- Joined: 2019-06-09T13:28:50-07:00
- Authentication code: 1152
multipage tiff file to array of regular images using ImageMagick functions
Hi Guys, please help me to get the ImageMagick API functions(C/C++ code snippet and not command line) that converts multipage tiff Image file data to array of regular images(jpg/png)... Thanks
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: multipage tiff file to array of regular images using ImageMagick functions
Please always provide your IM version when asking questions and platform/OS. What have you tried? Do you have any code?
-
- Posts: 4
- Joined: 2019-06-09T13:28:50-07:00
- Authentication code: 1152
Re: multipage tiff file to array of regular images using ImageMagick functions
I am using 64 bit windows 10 for development and my IM version details is as as follows
MagickppLibVersionText/MagickLibVersionText "7.0.0"
MagickppLibVersionNumber/MagickLibVersionNumber 1:0:0
JS Code Snippet:
I am passing proper TIFF fileData in _pData and size of _pData in _nSize to C function doing following things:
C - Code Snippet:
SO please suggest IM API methods to achieve the desired result
Thanks
MagickppLibVersionText/MagickLibVersionText "7.0.0"
MagickppLibVersionNumber/MagickLibVersionNumber 1:0:0
JS Code Snippet:
Code: Select all
if (e.target.result.split(',')[0].indexOf('tiff') > 0)
var fileData = e.target.result.split(',')[1];
C - Code Snippet:
Code: Select all
ExceptionInfo* exInfo = AcquireExceptionInfo();
ImageInfo* imInfo = CloneImageInfo(NULL);
//I now want _pData to decompress and convert into array of png/jpg image so that I can use each separate images and process that
Image* imImage = BlobToImage(imInfo, _pData, (size_t)_nSize, exInfo);
strcpy(imImage->magick, "bmp");
strcpy(imInfo->magick, "bmp");
unsigned char* ptr = (unsigned char*)::ImageToBlob(imInfo, imImage, (size_t*)&_imageDataSize, exInfo);
_imageData = new unsigned char[_imageDataSize];
memcpy(_imageData, ptr, _imageDataSize);
Thanks
-
- Posts: 4
- Joined: 2019-06-09T13:28:50-07:00
- Authentication code: 1152
Re: multipage tiff file to array of regular images using ImageMagick functions
_pData is the base64 decoded blob of Tiff image
-
- Posts: 4
- Joined: 2019-06-09T13:28:50-07:00
- Authentication code: 1152
Re: multipage tiff file to array of regular images using ImageMagick functions
Hi,
This can be done using BlobToImage() method present in blob.h of MagickCore and we can iterate through different images using the next pointer of Image* returned by BlobToImage() method as shown below
This can be done using BlobToImage() method present in blob.h of MagickCore and we can iterate through different images using the next pointer of Image* returned by BlobToImage() method as shown below
Code: Select all
//_pData is the base64 decoded blob of Tiff image
//_nSize is the sizeof _pData
//_imageData is the actual data of the image
ExceptionInfo* exInfoX = AcquireExceptionInfo();
ImageInfo* imInfoX = CloneImageInfo(NULL);
Image* imImageX = BlobToImage(imInfoX, _pData, (size_t)_nSize, exInfoX);
int EMSCRIPTEN_KEEPALIVE ImageControlWebAssembly::showGivenPageTiffImage(int pageNumber)
{
int count = 1;
try
{
if (imImageX == NULL)
{
return -1; //Handle this error
}
if (_imageData) {
delete[] _imageData;
}
_imageData = NULL;
_imageDataSize = 0;
ExceptionInfo* exInfo = AcquireExceptionInfo();
Image* temp = imImageX;
if (temp->next != NULL)
{
TRACE << _id << L"::imImage->next has info" << output();
while (count != pageNumber)
{
temp = temp->next;
count++;
}
//TRACE << _id << L":imImage->next has counts " << count << output();
}
strcpy(temp->magick, "bmp");
strcpy(temp->image_info->magick, "bmp");
unsigned char* ptr = (unsigned char*)::ImageToBlob(temp->image_info, temp, (size_t*)& _imageDataSize, exInfo);
_imageData = new unsigned char[_imageDataSize];
memcpy(_imageData, ptr, _imageDataSize);
free(ptr);
DestroyExceptionInfo(exInfo);
}
catch (std::exception& ex) {
//TRACE << _id << L"::]Magick::Exception " << ex.what() << output();
}
return count;
}