ios 如何把一个图片存入NSMutableDictionary并取出
-(void)setCurrentImage:(NSString*)serial_number//这个函数是inbackbrounk线程{。。。。NSData*data=...
-(void)setCurrentImage:(NSString*)serial_number//这个函数是inbackbrounk线程
{
。。。。
NSData * data = [NSDatadataWithContentsOfURL:[NSURLURLWithString:urlStr]];
UIImage* result = [UIImageimageWithData:data];
[selfperformSelectorOnMainThread:@selector(getImage:) withObject:result waitUntilDone:NO];
i++;
[m_gridViewsetNeedsDisplay];
}
-(void)getImage:(UIImage*)img{
NSString *key=[NSStringstringWithFormat:@"%d",i];
[imgDicsetObject:img forKey:key];
} 展开
{
。。。。
NSData * data = [NSDatadataWithContentsOfURL:[NSURLURLWithString:urlStr]];
UIImage* result = [UIImageimageWithData:data];
[selfperformSelectorOnMainThread:@selector(getImage:) withObject:result waitUntilDone:NO];
i++;
[m_gridViewsetNeedsDisplay];
}
-(void)getImage:(UIImage*)img{
NSString *key=[NSStringstringWithFormat:@"%d",i];
[imgDicsetObject:img forKey:key];
} 展开
1个回答
展开全部
NSMutableDictionary中的Object是id类型,应该是可以放UIImage的吧!
UIImage* result = [UIImageimageWithData:data];
[ imgDict setObject: result forKey:@"imgkey"];
UImage *img = (UIImage *)[imgDict objectForKey:@"imgkey"];
这种方法应该是可以的吧!
但是我认为不应该使用这种方法,因为你生成的image会很大,这样放在NSMutableDictionary中会占用大量的控件,我建议还是先存urlStr,到了该用这个UIImage的时候,再把这个urlStr取出来,生成UIImage。
UIImage* result = [UIImageimageWithData:data];
[ imgDict setObject: result forKey:@"imgkey"];
UImage *img = (UIImage *)[imgDict objectForKey:@"imgkey"];
这种方法应该是可以的吧!
但是我认为不应该使用这种方法,因为你生成的image会很大,这样放在NSMutableDictionary中会占用大量的控件,我建议还是先存urlStr,到了该用这个UIImage的时候,再把这个urlStr取出来,生成UIImage。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询