简体   繁体   English

调用'UIImagePickerController didFinishPickingMediaWithInfo'iOS7 XCode时的大量CPU使用情况

[英]Huge CPU usage when calling 'UIImagePickerController didFinishPickingMediaWithInfo' iOS7 XCode

I noticed a huge CPU usage when I press 'Use Photo' on UIImagePickerController calling the proper method: 当我在UIImagePickerController上按“使用照片”并调用正确的方法时,我发现CPU使用率很高:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

}

even if the method is empy! 即使方法是空的! Here an image logging CPU usage while above method is called. 在此调用上述方法时的图像日志记录CPU使用率。

图片

Top that I recorded was 169%. 我记录的最高成绩是169%。 So wtf?!? 那么wtf?!?

This is because size of the image that you are using is very large normally more than 2mb. 这是因为您使用的图像大小通常很大,通常大于2mb。 So so a image resize before using it. 因此,在使用前请调整图像大小。 here is the code snippet: 这是代码片段:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    if([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:@"public.image"]) {
    UIImage *originalImage = info[UIImagePickerControllerOriginalImage];

    if (!originalImage)
        return;

    // Optionally set a placeholder image here while resizing happens in background

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // Set desired maximum height and calculate width
        CGFloat height = 640.0f;  // or whatever you need
        CGFloat width = (height / self.view.frame.size.height) * self.view.frame.size.width;

        // Resize the image
        UIImage * image = [originalImage resizedImage:CGSizeMake(width, height) interpolationQuality:kCGInterpolationDefault];

        //save/use the image here
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, NULL);//for saving to camera roll
    });
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UIImagePickerController,当didFinishPickingMediaWithInfo未实现时 - UIImagePickerController, when didFinishPickingMediaWithInfo not implemented didFinishPickingMediaWithInfo 未在 Xcode 12 中调用 - didFinishPickingMediaWithInfo is not calling in Xcode 12 当 UIImagePickerController 委托 didFinishPickingMediaWithInfo 会被调用? - When UIImagePickerController delegate didFinishPickingMediaWithInfo will be called? UIImagePickerController didFinishPickingMediaWithInfo - UIImagePickerController didFinishPickingMediaWithInfo UIImagePickerController在didFinishPickingMediaWithInfo上关闭 - UIImagePickerController is dismissing on didFinishPickingMediaWithInfo UIImagePickerController didFinishPickingMediaWithInfo方向 - UIImagePickerController didFinishPickingMediaWithInfo Orientation 分配了cameraOverlyView属性时未调用UIImagePickerController didFinishPickingMediaWithInfo - UIImagePickerController didFinishPickingMediaWithInfo not being called when cameraOverlyView property is assigned 从库中选择视频时,uiimagepickercontroller didfinishpickingmediawithinfo NOT CALLED - uiimagepickercontroller didfinishpickingmediawithinfo NOT CALLED when selecting a video from the library UIImagePickerController:didFinishPickingMediaWithInfo 未被调用 - UIImagePickerController: didFinishPickingMediaWithInfo not being called UITableView仅在使用Xcode 5编译的iOS7上不调用didSelectRowAtIndexPath - UITableView not calling didSelectRowAtIndexPath on only iOS7 compiled with Xcode 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM