【发布时间】:2012-07-02 20:50:27
【问题描述】:
首先我从照片库中选择图像到 ALAsset 库,然后我将图像从 ALAsset 库路径存储在文档目录中。
我正在使用此代码将图像存储在 ALAsset 库中的文档目录中......它的工作完美......现在我想在表格视图中显示存储在文档目录中的所有图像......我该怎么做??? 谁能帮帮我??
将图像从 ALAsset 库导入到 NSdocument 目录的代码
for (int j=0; j<[assetArray count]; j++) {
ALAssetRepresentation *representation = [[assetArray objectAtIndex:j] defaultRepresentation];
NSString* filename = [documentPath stringByAppendingPathComponent:[representation filename]];
[[NSFileManager defaultManager] createFileAtPath:filename contents:nil attributes:nil];
NSOutputStream *outPutStream = [NSOutputStream outputStreamToFileAtPath:filename append:YES];
[outPutStream open];
long long offset = 0;
long long bytesRead = 0;
NSError *error;
uint8_t * buffer = malloc(131072);
while (offset<[representation size] && [outPutStream hasSpaceAvailable]) {
bytesRead = [representation getBytes:buffer fromOffset:offset length:131072 error:&error];
[outPutStream write:buffer maxLength:bytesRead];
offset = offset+bytesRead;
}
[outPutStream close];
free(buffer);
}
之后我使用此代码获取目录的内容:
NSFileManager *manager = [NSFileManager defaultManager];
fileList = [manager directoryContentsAtPath:newDir];
它也可以工作...但是现在当我想显示文档目录中的图像时。它没有显示任何东西......
setImage.image=[UIImage imageNamed:[filePathsArray objectAtIndex:0]];
谁能帮忙,问题出在哪里?????? - 我有一个疑问: *将图像从ALAsset库导入到文档目录是否正确???
【问题讨论】:
-
如果对您有帮助,请您标记我的答案是否正确!谢谢!!!
标签: iphone objective-c ios5 alassetslibrary nsdocumentdirectory