iphone - 处理 UIImagePickerController 压缩的最快方法

标签 iphone cocoa-touch uiimagepickercontroller uiimagejpegrepresentation

将图片放入 SQLite 数据存储进行压缩的最快方法是什么,以便我可以将控制权返回给用户?

  • 我正在使用 UIImagePickerController 在我的应用程序中拍照。问题是由于 UIImageJPEGRepresentation 的速度,使用图片的速度相当慢。
  • 我想将 JPEG 压缩插入后台线程,但在尝试此操作之前,我需要让自己确信我可以以跨运行的方式保留图片。这意味着 SQLite 中的 blob 或文件。据我所知,这让我立即回到进行慢速图片编码。

我想要实现的是速度足够快,让用户感觉是即时的。

我应该如何处理这个问题?还有什么我应该知道的吗?

最佳答案

根据评论和测试,这是我目前正在做的事情:

当我从 UIImageController 获取图像时,我将其保留在类 ivar 中并关闭图像选择器。我显示了一个阻止主视图的 View ,并安排一个 NSTimer 事件在一秒钟内进行压缩,然后返回给调用者。

这可以让动画运行并关闭图像 Controller 。我的拦截器 View 显示在其下方。

(拦截器 View 填充了导航 Controller 的整个内容区域,并且是纯黑色的,带有 UIActivityIndi​​catorView。)

- (void)imagePickerController: (UIImagePickerController *)picker
        didFinishPickingImage: (UIImage *)selectedImage
                  editingInfo: (NSDictionary *)editingInfo;
{
    busyView.userInteractionEnabled = YES;
    busyView.alpha = 0.7f;
    mainView.userInteractionEnabled = NO;
    [self dismissModalViewControllerAnimated: YES];
    [NSTimer scheduledTimerWithTimeInterval: 1.0f
                                     target: self
                                   selector: @selector(compress:)
                                   userInfo: selectedImage
                                    repeats: NO];
}

当计时器启动时,我使用 JPEG 压缩图像(因为它比 PNG 更快,尽管直觉如此)并淡出阻止 View 。

- (void)compress: (NSTimer *)inTimer;
{
    [self gotJPEG: UIImageJPEGRepresentation( inTimer.userInfo, 0.5f )];
    [UIView beginAnimations: @"PostCompressFade" context: nil];
    [UIView setAnimationDuration: 0.5];
    busyView.userInteractionEnabled = NO;
    busyView.alpha = 0.0f;
    [UIView commitAnimations];
    mainView.userInteractionEnabled = YES;
}

虽然这增加了第二次处理时间,但它可以更快地让图像选择器摆脱干扰,因此我不再感觉我的应用程序已卡住。 UIActivityIndi​​catorView 中的动画在 UIImageJPEGRepresentation 工作时运行。

比使用带有 1 秒延迟的 NSTimer 更好的答案是在 dismissModalViewControllerAnimated: 的动画完成时获取一个事件,但我不知道如何这样做。

(我认为这个问题还没有解决。)

关于iphone - 处理 UIImagePickerController 压缩的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1505278/

相关文章:

iphone - 下载普通图像与视网膜设备图像 (2x)

ios - Storyboard身份检查器中未显示自定义类

ios - 如何使用 iOS sdk 从视频中获取所选帧的开始和结束时间?

相机胶卷中的 ios UIImagePickerController?

iphone - UILocalNotification重复声音

ios - 如何在 iOS 中更改 titleForHeader 背景颜色?

iphone - 在 iOS 中使用 objectForKey 解析带有 NSJSONSerialization 类的 json

ios - 将图像从一个 View 传递到另一个 View

iphone - 为 iOS 更新分发证书的正确方法

iphone - 在 UIScrollView 中使用 CATiledLayer 进行缩放