-1

カメラから写真を取得し、その名前を使用してデータベースに保存したい...

私はこれらのコードを使用しました。私は正常に写真を撮り、画像ビューに追加しましたが、その名前 (文字列値) を取得できません

ImagePicker = [[UIImagePickerController alloc] init];
            ImagePicker.delegate = self;
            ImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentModalViewController:ImagePicker animated:YES];

- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo
{
    [ImagePicker dismissModalViewControllerAnimated:YES];
    imageview.hidden=NO;
    imageview.image = image;

    NSDate *today = [NSDate date];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
    NSString *dateString = [dateFormat stringFromDate:today];
    // save image in document directoties
    UIImage *image1=imageview.image;


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
    NSData *pngData = UIImageJPEGRepresentation(image1,100.0);
    NSString *filePath;
    filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"image%@.jpg",dateString]]; //Add the file name
    [pngData writeToFile:filePath atomically:YES]; //Write the file
    NSLog(@"File Path is %@",filePath);

    if (![[NSFileManager defaultManager] fileExistsAtPath:filePath])  //Optionally check if folder already hasn't existed.
    {
        NSLog(@"Unable to create Folder in Documents Directory");

    }

}
4

2 に答える 2

-1

正確な画像名を知ることは問題ではなく、選択した画像に一意の名前を付けることで目的が解決され、画像を保存してその名前で追跡できると思います。これはあなたを助けることができるかもしれません

//Fetch the Maximum id from DB
NSString* strSelect= [NSString stringWithFormat:@"Select MAX(id) from TableName"]; 
  NSMutableArray*  arr_test  = [[database executeQuery:strSelect]mutableCopy];

   //Check if it is the first Image or not
   if ([[[arr_test objectAtIndex:0]valueForKey:@"MAX(id)"]isKindOfClass:[NSNull class]])
        img_id = 1;

    else{
        NSString *strtest = [[arr_test objectAtIndex:0] valueForKey:@"MAX(id)"];
        img_id=[strtest intValue]+1;
    }

//Give the Image Name with Unique ID
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0];
filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/image%d.jpg",img_id]]; 
于 2013-10-26T10:56:40.467 に答える