【发布时间】:2010-07-21 05:38:05
【问题描述】:
我有一些图像数据以 BLOB 格式存储在 MySQL 数据库中,
我获取字符串和整数数据,但对于图像它不显示。
我也尝试过使用UIImageView,但它不起作用。
有人可以发布一些代码以在UITableView 中显示图像数据。
NSData-->UIImage-->图片展示。
谢谢
【问题讨论】:
标签: iphone mysql uitableview image uiimageview
我有一些图像数据以 BLOB 格式存储在 MySQL 数据库中,
我获取字符串和整数数据,但对于图像它不显示。
我也尝试过使用UIImageView,但它不起作用。
有人可以发布一些代码以在UITableView 中显示图像数据。
NSData-->UIImage-->图片展示。
谢谢
【问题讨论】:
标签: iphone mysql uitableview image uiimageview
给定一个 NSData 对象 data,其中数据是 UIImage 支持的图像类型(PNG、JPG、...)
/* These two are what I assume you start with */
char *rawData = [self getRawDataFromDB];
int rawDataLength = [self getLengthOfRawData];
/* To convert that to an image... */
UIImage *image = [UIImage imageWithData:[NSData dataWithBytes:rawData length:rawDataLength]];
一旦你有了图片,然后添加到你的 UITableViewDataSource 的tableView:cellForRowAtIndexPath:
[[cell imageView] setImage: image];
【讨论】: