如何在iphone中通过sqlite获取路径来显示文档目录中保存的图像
我已将图像保存在文档目录中,并成功地将其路径保存在数据库中。现在我不知道如何在图像视图中显示该图像 我应该使用查询只选择路径吗 它会自动从目录中选取图像吗 或者我应该使用代码在我想显示图像的视图中加载图像如何在iphone中通过sqlite获取路径来显示文档目录中保存的图像,iphone,ios,xcode,ipad,uiimageview,Iphone,Ios,Xcode,Ipad,Uiimageview,我已将图像保存在文档目录中,并成功地将其路径保存在数据库中。现在我不知道如何在图像视图中显示该图像 我应该使用查询只选择路径吗 它会自动从目录中选取图像吗 或者我应该使用代码在我想显示图像的视图中加载图像 -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSArray *paths = NSSearchP
-(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>
您可以使用
UIImage
的imageWithContentsOfFile
类方法
UIImage *image = [UIImage imageWithContentsOfFile:filePathFromDB];
查看包含
NSLog
语句的更新问题,您的[MyCommonFunctions saveImageInDocuments:image]
的NSLog
似乎是正确的。但您也向我们展示了您正在生成的SQL,它显然没有将[MyCommonFunctions saveImageInDocuments:image]
用作最后一个参数,而是您显然无意中获取了UIImageView
。看看构建SQL的代码。如果解决方案没有向您提出,请使用构建SQL的代码更新您的问题 通过在中使用此代码,我获得了此日志消息,用于图像2012-12-08 20:40:30.450 loginApp[757:c07]与DB 2012-12-08 20:41:05.371 loginApp[757:c07]连接成功,图像路径:08412012084105.png 2012-12-08 20:41:05.378 loginApp[757:c07]图像保存成功查询:插入登录(名称、电子邮件、密码、DOB、图像)值('hamesh','hamesh@hamesh.com","哈梅什","2012-12-09 04:40:57+0000",与db成功连接后查看我的日志消息这不是映像路径吗?我将您的NSLog
内容放在您的问题中,以便我可以阅读。请参阅下面的答案。我也使用NSString代替imageView,但使用了throggingexception@QualityCoder如果它抛出异常,可能是因为NSString
变量未被激活例如,设置正确且为nil
。看起来您正在调用[MyCommonFunctions saveImageInDocuments:image]
,但我看不到您将返回的文件名保存在何处。您需要将该文件名放在NSString
中以供将来参考,这是一个ivar,您将在调用authenticateRegistration
时使用。
- (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];
}
}
}
UIImage *image = [UIImage imageWithContentsOfFile:filePathFromDB];