要理解我的问题,请通过以下方式:
- 在我的应用程序中,用户首先点击一个按钮。
- 显示图像选择器控制器
- 用户从中选择图像/图像。
- 所有这些图像都必须保存到我的 iPhone 应用程序中。
我已经实现了这一点,为此我实现了以下代码。
-(IBAction)setPhoto:(id)sender {
facPhotoPicker=[[UIImagePickerController alloc]init];
facPhotoPicker.delegate=self;
facPhotoPicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
facPhotoPicker.allowsImageEditing=YES;
facPhotoPicker.navigationBar.barStyle=UIBarStyleBlackOpaque;
[self presentModalViewController:facPhotoPicker animated:YES];
}
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {
NSData *imgData=UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
UIImage *img=[[UIImage alloc] initWithData:imgData];
facImgView.image=img;
[img release];
NSString *str=[NSString stringWithFormat:@"%i.jpg",[currentFaculty facultyNo]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0], str];
[imgData writeToFile:path atomically:YES];
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
但问题是用户的 iPhone 可能有更大的图像。
我不想在应用程序中存储大图像。例如
- 用户选择大小为 1200 x 800 的图像
但我只想要 80 x 80 尺寸的图像
- 选定的图像应缩小到我的要求 / 8 mb 图像小于 500 kb
- 如何将图像存储在资源目录中而不是存储在文档目录中?