私の質問を理解するには、次の手順を実行してください。
- 私のアプリケーションでは、ユーザーは最初にボタンをタップします。
- イメージピッカーコントローラーが表示されます
- ユーザーが画像を選択するか、そこから画像を選択します。
- そのすべての画像を 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 未満にします
- ドキュメントディレクトリに保存するのではなく、リソースディレクトリに画像を保存する方法は?