针对SDPhotoBrowser不支持保存gif图片,提出的解决方法
2016-10-26 17:06
316 查看
最近在做图片预览和保存时候发现,SDPhotoBrowser保存的gif图片,竟变成了静态的gif图片,原以为iOS系统相册不支持GIF的播放,也就没注意,最后在微信发图的时候发现的确变成了静态gif图片,才知道这个出现了问题,在这个库里保存的是图片,而保存gif时候要保存数据流才不会变成静态图,最后解决方法如下:
- (void)saveImage{
int index =
_scrollView.contentOffset.x /
_scrollView.bounds.size.width;
/*
为了支持gif图片的存储此处改动原第三方库的内容如下:
与原库比对可发现
原来的
*/
// UIImageView *currentImageView = _scrollView.subviews[index];
// UIImageWriteToSavedPhotosAlbum(currentImageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
NSURL * url=[NSURL
URLWithString:[NSString
stringWithFormat:@"%@",[self
highQualityImageURLForIndex:index]]];
[[SDWebImageDownloader
sharedDownloader]
downloadImageWithURL:url
options:SDWebImageDownloaderUseNSURLCache
progress:nil
completed:^(UIImage *image,
NSData *data,
NSError *error,
BOOL finished) {
if ([UIDevice
currentDevice].systemVersion.floatValue >=
9.0f) {
[[PHPhotoLibrary
sharedPhotoLibrary]
performChanges:^{
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions
alloc]
init];
options.shouldMoveFile =
YES;
[[PHAssetCreationRequest
creationRequestForAsset]
addResourceWithType:PHAssetResourceTypePhoto
data:data options:options];
} completionHandler:^(BOOL success,
NSError * _Nullable error) {
dispatch_sync(dispatch_get_main_queue(), ^{
//保存成功
// [self image:<#(UIImage *)#> didFinishSavingWithError:<#(NSError *)#> contextInfo:<#(void *)#>]
[self
didFinishSavingWithError:error];
});
}];
}
else {
ALAssetsLibrary *library = [[ALAssetsLibrary
alloc] init];
[library writeImageDataToSavedPhotosAlbum:data
metadata:nil
completionBlock:^(NSURL *assetURL,
NSError *error) {
dispatch_sync(dispatch_get_main_queue(), ^{
//保存成功
[self
didFinishSavingWithError:error];
});
}];
}
}];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView
alloc]
init];
indicator.activityIndicatorViewStyle =
UIActivityIndicatorViewStyleWhiteLarge;
indicator.center =
self.center;
_indicatorView = indicator;
[[UIApplication
sharedApplication].keyWindow
addSubview:indicator];
[indicator startAnimating];
}
//保存结果提示语的出现以及indicator的消失
- (void)didFinishSavingWithError:(NSError *)error;
{
[_indicatorView
removeFromSuperview];
UILabel *label = [[UILabel
alloc] init];
label.textColor = [UIColor
whiteColor];
label.backgroundColor = [UIColor
colorWithRed:0.1f
green:0.1f
blue:0.1f
alpha:0.90f];
label.layer.cornerRadius =
5;
label.clipsToBounds =
YES;
label.bounds =
CGRectMake(0,
0, 150,
30);
label.center =
self.center;
label.textAlignment =
NSTextAlignmentCenter;
label.font = [UIFont
boldSystemFontOfSize:17];
[[UIApplication
sharedApplication].keyWindow
addSubview:label];
[[UIApplication
sharedApplication].keyWindow
bringSubviewToFront:label];
if (error) {
label.text =
SDPhotoBrowserSaveImageFailText;
} else {
label.text =
SDPhotoBrowserSaveImageSuccessText;
}
[label performSelector:@selector(removeFromSuperview)
withObject:nil
afterDelay:1.0];
}
相关文章推荐
- win7不支持GIF图片打开的两种解决方法
- 保存一个免费的在线的图片转换工具网站,支持BMP,JPG,IOC,PNG和GIF
- 通过web发布图片时,不论是什么格式的,在IE下保存时一律是“未命名.bmp”的原因和解决方法
- win7无法查看GIF图片的两种解决方法
- 保存图片时出现"800700de错误"的解决方法
- css 半透明 让IE6支持png图片半透明解决方法
- 使用DD_belatedPNG让IE6支持PNG透明图片 及IE6下背景图闪烁问题的解决方法
- 【android】把view保存为图片的方法以及解决保存后图片背景变黑色的问题
- JFreeChart生成折线图(生成图片本地保存,有解决中文乱码的通用方法)
- C++中使用CAtlHttpClient显示网络图片的方法,支持png,bmp,gif图片格式
- Rose图表保存成图片的解决方法
- GIF动画图片在IE中不能正常显示的解决方法
- 获取上传的图片并保存为缩略图,解决gif背景变黑问题
- 终于搞定多张JPG图片转成GIF动画这个难题,解决方法如下。
- 解决eWebEditor上传图片提示:请选择一个有效的文件,支持的格式有(GIF|JPG|JPEG|BMP|PNG)!
- 保存图片时出现"800700de错误"的解决方法
- 加载gif图片的方法:(需要SDWebImage方法)
- C++中使用CAtlHttpClient显示网络图片的方法,支持png,bmp,gif图片格式
- flex不显示GIF图片问题的另类解决方法