来自 sqlite 数据库的 ios 图像显示
<p><p>我已通过单击 <strong>saveInfo</strong> <strong>按钮</strong>将我的图像和文本保存到 <strong>sqlite3</strong> 数据库中。</p>
<pre><code>- (IBAction)saveInfo:(id)sender {
// Prepare the query string.
NSString *query;
if (self.recordIDToEdit == -1) {
query = ;
}
else{
query = ;
}
// Execute the query.--------------
;
// If the query is sucessfull the show this in the dubugger.
if (self.dbManager.affectedRows != 0) {
NSLog(@"Query was executed successfully. Affected rows = %d", self.dbManager.affectedRows);
// Here we inform the delegate that editing in app is finished.
;
// Pop the view controller.
;
}
else{
NSLog(@"%d",self.dbManager.affectedRows);
NSLog(@"---Could not execute the query.----");
}
}
</code></pre>
<p>然后我用这个方法加载数据,我可以访问文本数据但是不能用这个方法加载图像。</p>
<pre><code>-(void)loadInfoToEdit{
// Create the query.
NSString *query = ;
// Load the relevant data.
NSArray *results = [ initWithArray:];
// Setting the loaded data to the textfields and imageView.
.
self.txtEmpCode.text = [ objectAtIndex:];
self.txtName.text = [ objectAtIndex:];
self.txtDesignation.text = [ objectAtIndex:];
self.txtTagline.text = [ objectAtIndex:];
self.txtDepartment.text = [ objectAtIndex:];
self.saveImage.image = [ objectAtIndex:];
//NSLog(@"This photo has:%@",[objectAtIndex:]);
//self.saveImage.image= [objectAtIndex:];
// NSLog(@"This Nsdata object has %@",img);
// self.saveImage.image = ;
}
</code></pre>
<p>如何将我的图像加载到 <strong>saveImage(UIImageView 属性)</strong>?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您应该将图像保存在文档目录中。为此,您应该首先将图像转换为数据,然后将该数据保存(或写入)到 <code>documentdirectory</code>。并且您应该将图像名称保存到您的 <code>sqlite 数据库</code></p>
<p>现在,当您从数据库中获取数据时,您将获得 imagename,通过该 <code>imagename</code> 您可以从 <code>document directory</code> 获取您保存的图像数据,然后您可以将其转换数据图像,可以根据需要使用。</p>
<p>例子:</p>
<p>保存图片,</p>
<pre><code> NSString *docsDir = ;
NSString *profilePicturePath = ;
NSData *data = UIImageJPEGRepresentation(yourImage, 1.0);
;
</code></pre>
<p>您可以检索图像,</p>
<pre><code> UIImage *img = ];
</code></pre></p>
<p style="font-size: 20px;">关于来自 sqlite 数据库的 ios 图像显示,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38481828/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38481828/
</a>
</p>
页:
[1]