嗨朋友,我正在将图像保存在文档目录中,就像在文档目录中一样,图像像 saveimage0.png,saveimage1.png ......等这样的图像被输入到文档中,我创建 int 变量用于增量计数,图像 num=0;插入工作正常但是如何从 loadimage menthod 中的文档文件夹获取多个图像是对还是错我想要 tkae 图像并保存在数组中并显示在视图中
int num=0;
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info
objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info
objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = image;
UIImage *image1 =imageView.image;
NSData *myData = [UIImagePNGRepresentation(image1) retain];
imagedata = myData;
if (newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
@selector(image:finishedSavingWithError:contextInfo:),
nil);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"saveimage%d.png",num]];
num += 1; // for next t
NSData* data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
我正在从文档目录中获取图像,与
int value;
- (UIImage*)loadImage
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// NSString* path = [documentsDirectory stringByAppendingPathComponent:
//[NSString stringWithString: @"test.png"] ];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat: @"savedImage-",@"%@-%d.png", value]];
value += 1;
UIImage* image = [UIImage imageWithContentsOfFile:path];
return image;
}