1

我已将图像保存在文档目录中并成功将其路径保存在数据库中,现在我不知道如何在我的图像视图中显示该图像?

我应该使用查询来仅选择路径吗?

它会自动从目录中选择图像吗?

或者我应该在我想要显示图像的视图中使用代码来加载图像。

-(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];
                }
            }
        }
4

2 回答 2

0

可以使用imageWithContentsOfFile类方法UIImage

UIImage *image = [UIImage imageWithContentsOfFile:filePathFromDB];
于 2012-12-09T04:29:54.823 回答
0

查看包含陈述的更新问题,您的NSLog似乎是正确的。但是您还向我们展示了您正在生成的 SQL,显然它没有将它用于最后一个参数,而是您显然不小心抓取了一个. 查看构建该 SQL 的代码。如果解决方案没有突然出现,请使用构建 SQL 的代码更新您的问题。NSLog[MyCommonFunctions saveImageInDocuments:image][MyCommonFunctions saveImageInDocuments:image]UIImageView

于 2012-12-09T05:40:59.747 回答