gpt4 book ai didi

ios - 图像是由 UIImagePickerControllerSourceTypeCamera 拍摄的如何将其保存在 ios 的数据库中

转载 作者:行者123 更新时间:2023-11-29 12:26:34 24 4
gpt4 key购买 nike

.m 编码

-(IBAction) getPhoto:(id) sender {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

} else {
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"You don't have a camera for this device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

//shows above alert if there's no camera
[noCameraAlert show];
}else{
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = YES;
picker.delegate = self;
}
}
[self presentViewController:picker animated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];
img = [info valueForKey:UIImagePickerControllerEditedImage];
self.imageView.image = img;
imagData = UIImagePNGRepresentation(img);
[picker dismissViewControllerAnimated:YES completion:nil];
}

现在图像已放在 ImageView 中,我如何将图像保存在数据库中

我已经有了数据库来插入数据插入:

NSMutableArray *listItemsarr = [[NSMutableArray alloc] init];
if([listItemsarr count]==0){
NSString *insertQry=@"INSERT INTO selection_tbl (expenses_value,category,date,payment,description) VALUES(?,?,?,?,?)";
sqlite3_stmt *stmt=[DB OpenSQL:[insertQry UTF8String]];
if(stmt !=nil)
{
sqlite3_bind_text(stmt,1, [dataTextfield.text UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,2, [[selectionarray objectAtIndex:0] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,3, [[selectionarray objectAtIndex:1] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,4, [[selectionarray objectAtIndex:2] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,5, [[selectionarray objectAtIndex:3] UTF8String], -1, SQLITE_TRANSIENT);


sqlite3_step(stmt);
}
sqlite3_finalize(stmt);
[DB CloseSQL];

以下代码用于更新数据库值更新:

NSInteger proeditid = [primarykeyID integerValue];
NSString *updateQry=@"update selection_tbl set expenses_value=?,category=?,date=?,payment=?,description=? where expenses_id=?";
sqlite3_stmt *stmt=[DB OpenSQL:[updateQry UTF8String]];
if(stmt !=nil)
{
sqlite3_bind_text(stmt,1, [dataTextfield.text UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,2, [[selectionarray objectAtIndex:0] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,3, [[selectionarray objectAtIndex:1] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,4, [[selectionarray objectAtIndex:2] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt,5, [[selectionarray objectAtIndex:3] UTF8String], -1, SQLITE_TRANSIENT);


sqlite3_bind_int(stmt,6, (int)proeditid);
sqlite3_step(stmt);
}
sqlite3_finalize(stmt);
[DB CloseSQL];

最佳答案

有两个问题:

  1. 如何获取 NSData图像的表示?

  2. 如何保存 NSData SQLite 数据库中的表示?

    保存这个NSData在您的数据库中,然后使用 sqlite3_bind_blob .该过程与 sqlite3_bind_xxx 非常相似您之前与我们分享的功能。使用 bytes NSData的方法|访问指向缓冲区的 C 样式指针,并将其传递给 sqlite3_bind_blob .

请注意,众所周知,在 SQLite 数据库中保存全尺寸图像效率低下。 SQLite 不能很好地处理大的 blob。通常人们更愿意保存 NSData到设备永久存储上的文档文件夹中的一个文件中,然后只保存 path数据库中的那个文件。

关于ios - 图像是由 UIImagePickerControllerSourceTypeCamera 拍摄的如何将其保存在 ios 的数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28935879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com