2011-07-30 14 views
0

イメージをUIImagePickerのものから取り出して、サンドボックス環境、ドキュメントフォルダなどに一時的に保存したい。しかし、私はこれを行う方法を知らない、誰かが私を助けることができますか?おかげイメージをサンドボックスに保存する方法 - iPhone SDK

瞬間画像UIImageである

+0

を参照してください:http://stackoverflow.com/質問/ 5794422/iphone-save-uiimage-to-desktop-on-simulator –

+0

これは良いことですが、離れていてもデスクトップに保存したくないコードがデバイス上で実行されているときに多くを使用してください – Jon

答えて

12

画像を保存:

-(void)saveImage:(UIImage*)image{ 
    NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/someImageName.png"]; 

    [UIImagePNGRepresentation(image) writeToFile:imagePath atomically:YES]; 

} 

画像をロード

-(UIImage)loadImage{ 

    NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/someImageName.png"]; 

    UIImage *image = [UIImage imageWithContentsOfFile:imagePath]; 
} 
+0

ありがとう、これは素晴らしいです – Jon

+0

それがあなたの問題plsを解決すれば、答えを受け入れてください。 – Cyprian

1
-(void)SaveImage 

{ 

NSData *data; 

NSArray *paths; 

NSString *documentsDirectory,*imagePath ; 

UIImage *image=[UIImage imageNamed:@"public.png"]; 

paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

documentsDirectory = [paths objectAtIndex:0]; 

imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"public.png"]]; 

data = UIImagePNGRepresentation(image); 

[data writeToFile:imagePath atomically:YES]; 

} 
関連する問題