zoukankan      html  css  js  c++  java
  • 从系统相册中选择GIF图片上传到服务器

    -(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图片的路径来上传

  • 相关阅读:
    计算一个数的逆序数的个数(1)
    Javascript DOM(2)
    python 装饰器
    Javascript DOM
    Javascrip 入门第三节课
    C# sapnco支持.net 4.5了,真是个意外的发现
    uft调用rfc接口
    pyqt常用窗口组件
    python QQTableView中嵌入复选框CheckBox四种方法
    Pygame模块,功能表
  • 原文地址:https://www.cnblogs.com/hw140430/p/4528420.html
Copyright © 2011-2022 走看看