zoukankan      html  css  js  c++  java
  • ALAssets的两种用法

    一:

    ALAssetsGroupEnumerationResultsBlock resultsBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) {

            if (result && [[result valueForProperty:ALAssetPropertyType] isEqual:ALAssetTypePhoto]) {

                ZWPhoto *aPhoto = [[ZWPhoto alloc] initWithAsset:result];

                aPhoto.checked = false;

                aPhoto.originPhotoNeeded = false;

                

                [self.photosArray addObject:aPhoto];

            } else if (self.photosArray.count > 0) {

                [self.collectionView reloadData];

            }

        };

        

        [self.assetsGroup enumerateAssetsUsingBlock:resultsBlock];

     

    二:

    self.assetsLibrary = [[ALAssetsLibrary alloc] init];

        dispatch_queue_t dispatchQueue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

        dispatch_async(dispatchQueue, ^(void) {

            // 遍历所有相册

            [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll

                                              usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

                                                  // 遍历每个相册中的项ALAsset

                                                  [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index,BOOL *stop) {

                                                      

                                                      __block BOOL foundThePhoto = NO;

                                                      if (foundThePhoto){

                                                          *stop = YES;

                                                      }

                                                      // ALAsset的类型

                                                      NSString *assetType = [result valueForProperty:ALAssetPropertyType];

                                                      if ([assetType isEqualToString:ALAssetTypePhoto]){

                                                          foundThePhoto = YES;

                                                          *stop = YES;

                                                          ALAssetRepresentation *assetRepresentation =[result defaultRepresentation];

                                                          CGFloat imageScale = [assetRepresentation scale];

                                                          UIImageOrientation imageOrientation = (UIImageOrientation)[assetRepresentation orientation];

                                                          dispatch_async(dispatch_get_main_queue(), ^(void) {

                                                              CGImageRef imageReference = [assetRepresentation fullResolutionImage];

                                                              // 对找到的图片进行操作

                                                              UIImage *image =[[UIImage alloc] initWithCGImage:imageReference scale:imageScale orientation:imageOrientation];

                                                              _myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];

                                                              _myImageView.image = image;

                                                              [self.view addSubview:_myImageView];

                                                              if (image != nil){

                                                                  //获取到第一张图片

                                                              } else {

                                                                  NSLog(@"Failed to create the image.");

                                                              } });

                                                      }

                                                  }];

                                              }

                                            failureBlock:^(NSError *error) {

                                                NSLog(@"Failed to enumerate the asset groups.");

                                            }];

            

        });

  • 相关阅读:
    JS 表单submit() 提交无效的问题
    thinkphp中连接oracle时封装的方法无法用
    Struts2 开发流程(转)
    oracle wm_concat(column)函数的使用(转)
    js点击按钮后显示时间自动减少提示
    Windows Server 2008 R2安装过程
    Spring学习之旅(1) 第一个Controller
    Groovy系列 Groovy集合
    Groovy系列 安装Groovy
    VMWare实现共享目录
  • 原文地址:https://www.cnblogs.com/wskgjmhh/p/4864729.html
Copyright © 2011-2022 走看看