使用ALAssetsLibrary和ALAsset取出图片的NSData

阅读更多

 使用ALAssetsLibrary和ALAsset取出图片的NSData

1

ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
  [assetLibrary assetForURL:[[self.imagedata objectAtIndex:i] valueForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) 
  {
   ALAssetRepresentation *rep = [asset defaultRepresentation];
   Byte *buffer = (Byte*)malloc(rep.size);
   NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
   NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];//this is NSData may be what you want
   [data writeToFile:photoFile atomically:YES];//you can save image later
  } 
  failureBlock:^(NSError *err) {
   NSLog(@"Error: %@",[err localizedDescription]);
  }];

 

2.

UIImage * selImage = [UIImage imageWithCGImage:[asset thumbnail]];  
NSData *baseImage=UIImagePNGRepresentation(selImage);

 

你可能感兴趣的:(使用ALAssetsLibrary和ALAsset取出图片的NSData)