Я пытаюсь получить значок сайта, который я сохранил в sqlite. При получении NSData это не ноль, но когда я пытаюсь преобразовать в UIImage - UIImage в ноль. Существует мой код:Как получить UIImage из NSData SQLite blob
-(NSMutableArray *) historyList{
sqlite3 *db;
thehistory = [[NSMutableArray alloc] initWithCapacity:100];
@try {
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = strMessage;
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured: %s", sqlite3_errmsg(db));
}
const char *sql = "SELECT * FROM HITSORY";
sqlite3_stmt *sqlStatement;
if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
{
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}else{
while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
HistoryOBJ *author = [[HistoryOBJ alloc]init];//this is NSObject
author.title = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
author.url = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,2)];
NSData *imageData = [[NSData alloc] initWithBytes:sqlite3_column_blob(sqlStatement, 3) length: sqlite3_column_bytes(sqlStatement, 3)];
//imageData is saved favicon from website.
if (imageData!=nil) {
NSLog(@"THERE imageData IS NOT NIL");//There data is not nil.
}
UIImage *image = [UIImage imageWithData:imageData];
Там Я получаю ошибку, что image
всегда равна нулю.
if (image==nil) {
NSLog(@"THERE image IS NIL");//There is my problem
}
author.icon = image;//author.icon is UIImage variable
[thehistory addObject:author];
}
}
}
@catch (NSException *exception) {
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}
@finally {
sqlite3_close(db);
return thehistory;
}
}
Что мне там недостает?
Я предполагаю, что изображение было повреждено, прежде чем вы его сохранили. –