0

我在 ios 上使用 Image Magick,并且已将服务器上使用的一些命令行转换为 ConvertImageCommand。一切正常。我已将 -monitor 作为参数添加到命令中,这样我就可以看到图像上的每一个微小进展(加载、调整大小、裁剪等)

但是,我想显示一个进度条来通知用户图像处理的进度。我正在寻找一个关于如何使用进度监视器功能的非常简单的例子......

SetImageProgressMonitor(Image *,const MagickProgressMonitor,void *),
SetImageInfoProgressMonitor(ImageInfo *,const MagickProgressMonitor,void *);

有人可以帮助我吗?

4

1 回答 1

0

这是代码:

- (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];
}
于 2013-01-04T11:51:57.953 回答