码迷,mamicode.com
首页 > Web开发 > 详细

从系统相册中选择GIF图片上传到服务器

时间:2015-05-25 18:12:37      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

-(void)assetPickerController:(ZYQAssetPickerController *)picker didFinishPickingAssets:(NSArray *)assets
{
    for (int i = 0; i < assets.count; i ++) {
        ALAsset *asset = assets[i];
        ALAssetRepresentation *rep = [asset defaultRepresentation]; 
       
        if ([rep.UTI hasSuffix:@"gif"]) {//选中的是gif
       
            //拼接gif的文件路径
            NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *filePath = [document stringByAppendingPathComponent:rep.filename];
     
            BOOL fileExist = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
            if (!fileExist) {//选中的gif还未写入到沙盒
               
                //把选中的gif写入到沙盒中
                Byte *imageBuffer = (Byte*)malloc(rep.size);
                NSUInteger bufferSize = [rep getBytes:imageBuffer fromOffset:0.0 length:rep.size error:nil];
                NSData *imageData = [NSData dataWithBytesNoCopy:imageBuffer length:bufferSize freeWhenDone:YES];
                [imageData writeToFile:filePath atomically:YES];
            }
            [_selectImages addObject:filePath];
        }
    }
}

//然后根据写入到沙盒中的GIF图片的路径来上传

从系统相册中选择GIF图片上传到服务器

标签:

原文地址:http://www.cnblogs.com/hw140430/p/4528420.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!