7

私はiPhoneアプリ開発の初心者です。保存フィールドとしてSQLデータベースを使用して、登録ページ、ログインページ、およびプロファイルを含むiPhoneアプリを作成しました。写真をプロファイル写真として保持したいです。すでに保存されている写真から選択しましたシミュレーターからの写真。もう一度実行すると、その写真をそのままにしておきたい....助けてください...

4

2 に答える 2

2

イメージをアプリケーション バンドルに保存し、アプリケーションのロード時にイメージを取得できます。

ここにあなたのためのチュートリアルがあります:

http://www.friendlydeveloper.com/2010/02/using-nsfilemanager-to-save-an-image-to-or-loadremove-an-image-from-documents-directory-coding/

于 2012-06-20T10:26:11.137 に答える
0

imagepicker を使用してギャラリーから選択した画像の画像を取得する場合は、これを使用します。

   -(void)saveImageInDirectoryAndStoreInDatabase
   {
     NSArray  *paths        = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
    NSString *imgFilePath  = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",youruserName];

     NSData *data = UIImagePNGRepresentation(youruserImage) //which is obtained from imagepicker
    [data writeToFile:imgFilePath atomically:YES];
     //query here into database with imageFile(A string) which is[NSString stringWithFormat:@"%@.png",youruserName];
   }

同様に、画像を取得する場合は、documentDirectory+imageFile.png (imageFile でユーザー名をクエリすることによってデータベースから取得される) パスを使用して、ユーザー プロファイルの pic を設定します。

于 2012-06-20T10:36:00.513 に答える