如何从ALAssetsLibrary获取真实图像

时间:2014-12-29 09:23:38

标签: objective-c ios7

我想从ALAssetsLibrary获取图片。我使用下面的代码。但它不起作用。我的原始图像大小是2448×3264.But以下代码的结果图像是640 X 852.我想原始图像大小2448 X 3264.任何帮助将非常感谢。

ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
                    [assetLibrary assetForURL:[[self.chosenImages objectAtIndex:i] valueForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset)
                     {
                         ALAssetRepresentation *rep = [asset defaultRepresentation];
                         uint8_t *buffer = (uint8_t *)malloc(sizeof(uint8_t)*[rep size]);

                         NSUInteger buffered = (NSInteger )[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
                         UIImage *myImg =[UIImage imageWithData:data];
                          NSLog(@"myImg width and height %f and %f",myImg.size.width ,myImg.size.height);

                     }
                    failureBlock:^(NSError *err) {
                                     NSLog(@"Error: %@",[err localizedDescription]);
                    }];

0 个答案:

没有答案