BSXPCMessage received error for message: Connection interrupted
来源:互联网 发布:js将空数组转换为数字 编辑:程序博客网 时间:2024/05/20 15:40
博主在做关于CIImage类时遇到了这个问题;
BSXPCMessage received error for message: Connection interrupted;
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info中,使用
UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];得到原图;
然后CIImage *tempImage = [CIImageimageWithCGImage:image.CGImage];得到CIImage;
这时操作的CIImage就会报错;博主搜遍了谷歌百度,见外国的开发者有提到内存的问题,便想到了压缩图片.果然,压缩之后便不报错了.
废话不多少,直接上代码!
//按宽度压缩图片!
+ (UIImage *) imageCompressForWidth:(UIImage *)sourceImage targetWidth:(CGFloat)defineWidth{
UIImage *newImage =nil;
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = defineWidth;
CGFloat targetHeight = height / (width / targetWidth);
CGSize size =CGSizeMake(targetWidth, targetHeight);
CGFloat scaleFactor =0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
CGPoint thumbnailPoint =CGPointMake(0.0,0.0);
if(CGSizeEqualToSize(imageSize, size) ==NO){
CGFloat widthFactor = targetWidth / width;
CGFloat heightFactor = targetHeight / height;
if(widthFactor > heightFactor){
scaleFactor = widthFactor;
}
else{
scaleFactor = heightFactor;
}
scaledWidth = width * scaleFactor;
scaledHeight = height * scaleFactor;
if(widthFactor > heightFactor){
thumbnailPoint.y = (targetHeight - scaledHeight) *0.5;
}elseif(widthFactor < heightFactor){
thumbnailPoint.x = (targetWidth - scaledWidth) *0.5;
}
}
UIGraphicsBeginImageContext(size);
CGRect thumbnailRect =CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width = scaledWidth;
thumbnailRect.size.height = scaledHeight+1;
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
if(newImage ==nil){
debugLog(@"scale image fail");
}
UIGraphicsEndImageContext();
return newImage;
}
上面是按宽度压缩图片的代码,压缩率不算高,但是可以用.也可以用其他方法;
UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];//得到原图
UIImage *imageAfterCompress = [MYToolsimageCompressForWidth:imagetargetWidth:640.f];//按宽度640压缩图片
CIImage *tempImage = [CIImageimageWithCGImage:imageAfterCompress.CGImage];//得到CIImage,此时操作CIImage就不会报错了
NSArray *features = [self.detectorfeaturesInImage:tempImage];
- BSXPCMessage received error for message: Connection interrupted
- 【iOS】BSXPCMessage received error for message: Connection interrupted的解决办法
- 两个脑仁疼的error:error in __connection_block_invoke_2: Connection interrupted
- 【zookeeper】Interrupted while waiting for message on queue
- XPC connection interrupted in Xcode 7 for iOS 9
- "This connection is untrusted" - Firefox error message
- 真机运行出现An unknown error message 'DeviceLocked', was received from the device.提示
- ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after XXX ms
- err = Problems with launching via XPC. XPC error : Connection interrupted (0x00000005)
- ActiveMQ使用STOMP协议的一个错误问题:Unexpected ACK received for message-id
- org.codehaus.xfire.fault.XFireFault: Not enough message parts were received for the operation.
- WebService调用时的异常:Not enough message parts were received for the operation
- 由jdveloper运行不起的解决办法 <Received exception while creating connection for pool "Connection1": ORA-01033:
- MESSAGE: Software caused connection abort: socket write error异常
- 解决'RedisException' with message 'read error on connection'
- 解决phpredis 'RedisException' with message 'read error on connection'
- Error 270 for archive log file ORA-00270: error creating archive log Error 1033 received logging on
- CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.
- [ASP.NET MVC 小牛之路]16 - Model 验证
- Java中的继承与组合
- MyEclipse或者Eclipse控制台(Console)中的中文输出乱码问题
- POJ二叉树
- 服务器编码
- BSXPCMessage received error for message: Connection interrupted
- RHEL三(输入输出重定向、管道符)
- linux 用户管理
- Mysql开启远程连接方法
- android AsyncTask介绍
- 8、编写一个程序,它先将键盘上输入的一个字符串转换成十进制整数, 然后打印出这个十进制整数对应的二进制形式。
- Unity多线程(Thread)和主线程(MainThread)交互使用类——Loom工具分享
- 【Linux_Fedora_应用系列】_5_如何安装XZ Utils 解压缩工具以及利用 xz工具来解压缩.xz文件
- QT5.3.1移植(上)