欢迎光临小挖掘机网站,专业制造厂家,拥有20年的制造经验,高品质满足客户的需求!

小挖掘机网站

微型钩机规格型号齐全,当天发货,货到付款,欢迎来电咨询!

[儿童小挖掘机玩具图片大全大图]iOS展示超大图片或超高分辨率图片崩溃解决方法

作者:jcmp      发布时间:2021-04-24      浏览量:0
一、参考:二、实现://先从内存中查找

一、参考:

二、实现:

//先从内存中查找,查找不到再解码,避免重复解码UIImage *cacheImage = [self.photoBrowser cacheImageWithPhoto:_photo];if (cacheImage == nil) { //不存在,解码 [self.photoBrowser showHUDWithSuperBigPhoto]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ CGSize compressSize = CGSizeMake(XXPhotoCompressPixelMax, XXPhotoCompressPixelMax); if (image.size.width > image.size.height) { compressSize = CGSizeMake(XXPhotoCompressPixelMax, XXPhotoCompressPixelMax*image.size.height/image.size.width); } else { compressSize = CGSizeMake(XXPhotoCompressPixelMax*image.size.width/image.size.height, XXPhotoCompressPixelMax); } UIImage *compressedImage = [image imageByScalingProportionallyToSize:compressSize]; dispatch_async(dispatch_get_main_queue(), ^{ [self.photoBrowser cacheImageWithPhoto:_photo image:compressedImage]; self.showImageView.image = compressedImage; [self.photoBrowser hideHUDWithSuperBigPhoto]; [self resetSize]; }); });}else { //直接使用 self.showImageView.image = cacheImage;}

- (void)didCutImage { if (_orImage) { if (self.scrollView.contentSize.width >= kScreenWidth && self.scrollView.contentSize.height >= kScreenHeight) { CGFloat multipleF = _orImage.size.width/self.scrollView.contentSize.width; CGFloat width = kScreenWidth*multipleF; CGFloat height = kScreenHeight *multipleF; //如果剪切的尺寸过大,不处理 if (width > XXPhotoPixelMax || height > XXPhotoPixelMax) { return; } //如果剪切的尺寸过大,不处理 //裁剪展示视图 if (_bigCupImageView) { _bigCupImageView.frame = CGRectMake(self.scrollView.contentOffset.x, self.scrollView.contentOffset.y, kScreenWidth, kScreenHeight); } else { [self.scrollView addSubview:self.bigCupImageView]; } //裁剪展示视图 CGImageRef cgRef = _orImage.CGImage; CGImageRef imageRef = CGImageCreateWithImageInRect(cgRef, CGRectMake(self.scrollView.contentOffset.x *multipleF ,self.scrollView.contentOffset.y *multipleF, width, height)); UIImage *thumbScale = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); self.bigCupImageView.image = thumbScale; } }}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { [NSObject cancelPreviousPerformRequestsWithTarget:self]; [self performSelector:@selector(didCutImage) withObject:nil afterDelay:.5];}

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view { if (_bigCupImageView) { [_bigCupImageView removeFromSuperview]; _bigCupImageView = nil; }}

三、结语:

此解决方式在实现上非常简单,开始只是困于思路。如果你有其他的方式,那我们就开始一段愉快的交流吧!