我已将图像保存在文档目录中并成功将其路径保存在数据库中,现在我不知道如何在我的图像视图中显示该图像?
我应该使用查询来仅选择路径吗?
它会自动从目录中选择图像吗?
或者我应该在我想要显示图像的视图中使用代码来加载图像。
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *strimagename;
strimagename=[NSString stringWithFormat:@"Test.jpg"];
thumbFilePath = [documentsDirectory stringByAppendingPathComponent:strimagename];
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSLog(@"image path: %@ ", [MyCommonFunctions saveImageInDocuments:image]);
imageSelect.image = image;
[self dismissModalViewControllerAnimated:YES];
NSLog(@"image saved %@",image);
}
上面的代码用于保存。
通过使用此代码,我得到此图像的日志消息:
2012-12-08 20:40:30.450 loginApp[757:c07] CONNECTION SUCCESSFUL WITH DB
2012-12-08 20:41:05.371 loginApp[757:c07] image path: 08412012084105.png
2012-12-08 20:41:05.378 loginApp[757:c07] image saved <UIImage: 0x926da00>
成功查询:
insert into login(Name,Email,Password,DOB,image) values('hamesh', 'hamesh@hamesh.com','hamesh','2012-12-09 04:40:57 +0000','<UIImageView: 0x926d8f0; frame = (139 219; 133 115); opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x926d950>>')
在这里我正在使用构建 Sql 的代码,在图像中我应该提供属性 NSString 吗?还是图像视图?
- (IBAction)registerbtn:(id)sender {
DBHandler *db =[[DBHandler alloc]init];
if([self validateForm])
{
if([self validateEmailWithString:txtEmail.text])
{
if ([db authenticateRegistration:txtName.text andEmail:txtEmail.text andPassword:txtPassword.text andDob:txtDob.text andImage:imageSelect])
{
UIAlertView *loginalert = [[UIAlertView alloc] initWithTitle:@" Congrats" message:@"SignUp Success" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[loginalert show];
}
else
{
UIAlertView *loginalert = [[UIAlertView alloc] initWithTitle:@" Try Again!" message:@"SignUp Failure" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[loginalert show];
}
}
}