Here is the code I am using:
Code: Select all
int main( int argc, char ** argv)
{
Magick::InitializeMagick(*argv);
std::string filePath = "C:\\test.psd";
std::string fileName = filePath;
RemoveFileNamePath( fileName );
RemoveFileNameExtension( fileName );
ImageInfo* image_info = CloneImageInfo((ImageInfo *) NULL);
strncpy_s(image_info->filename, filePath.c_str(), MaxTextExtent - 1);
ExceptionInfo exception;
GetExceptionInfo(&exception);
printf( "Processing File: %s\n\n", filePath.c_str() );
Image* image = ReadImage( image_info, &exception );
// Loop through all the layers
for ( ; image != (Image *)NULL; image = GetNextImageInList(image) )
{
// Get layer name
const char* szLayerName = GetImageProperty( image, "label" );
if( !szLayerName || szLayerName[0] != '.' )
continue;
std::string outFileName( fileName );
outFileName += szLayerName;
std::string outFilePath( "C:\\" );
outFilePath += outFileName;
outFilePath += ".tif";
std::transform( outFilePath.begin(), outFilePath.end(), outFilePath.begin(), tolower );
strncpy_s( image->filename, outFilePath.c_str(), MaxTextExtent - 1 );
strncpy_s( image_info->filename, outFilePath.c_str(), MaxTextExtent - 1 );
printf( "\tSaving layer %s as file %s... ", szLayerName, outFilePath.c_str() );
// Write out layer.
WriteImage( image_info, image );
printf( "Complete\n" );
}
/* Clean up */
DestroyImageInfo( image_info );
(void)DestroyExceptionInfo( &exception );
DestroyMagick();
printf( "\nProcessing Complete.\n\n" );
system("PAUSE");
return 0;
}
Any help would be appreciated!