Hi,
Thank you very much for your help. I achieved the setup of the monitor.
However, I would like to know if there is a simple way to define the number of operations which will be proceed (monitored) before the execution of the command line.
For example, the command "convert imgSource.jpg -blur 0x2.5 -paint 5 imgSaved.jpg" execute 4 operations : Load, Blur, OilPaint and Save.
But the command "convert ((-size 765x523 xc:black -virtual-pixel Transparent (( imgSource.jpg -resize x358 -gravity center -crop 277x358+0+0 +repage ) -matte +distort Perspective 0,0 180,163 0,358 230,522 277,358 469,431 277,0 455,134 ) -layers merge +repage imgBackground.jpg -compose dst-in -composite ) ) imgSaved.png" execute only 3 operations.
Also, for the others who have the same issue, here is my code:
Code: Select all
- (void)ExecuteCommand {
/*
command is an array which contains all the elements of the ImageMagick command.
example:
command (
convert,
imgSource.jpg,
"-blur",
"0x2.5",
"-paint",
5,
imgSaved.jpg
)
*/
ImageInfo *imageInfo = AcquireImageInfo();
int nbArgs = command.count;
char **argv = (char **)malloc((nbArgs + 1) * sizeof(char*));
for (unsigned i = 0; i < nbArgs; i++)
{
NSString *argString = [command objectAtIndex:i];
argv[i] = strdup([argString UTF8String]);
}
argv[nbArgs] = NULL;
progress_monitor_method = SetImageInfoProgressMonitor(imageInfo, &MonitorProgress, self);
ConvertImageCommand(imageInfo, nbArgs, argv, NULL, AcquireExceptionInfo());
if (argv != NULL)
{
for (unsigned index = 0; argv[index] != NULL; index++) {
free(argv[index]);
}
free(argv);
}
}
MagickBooleanType MonitorProgress(const char *text,const MagickOffsetType offset,const MagickSizeType extent,void *client_data) {
IM_TestViewController *IMVC = client_data;
float prog = offset;
float tot = extent;
NSNumber *value = [NSNumber numberWithFloat:prog/tot];
[IMVC performSelectorInBackground:@selector(updateProgressBar:) withObject:value] ;
NSLog(@"Action : %@ %lld on %lld", [NSString stringWithCString:text encoding:NSUTF8StringEncoding], offset, extent);
return MagickTrue;
}
- (void)updateProgressBar:(NSNumber *)value {
self.progressBar.progress = [value floatValue];
}