1. UIView -> UIImage
-(UIImage *)getImageFromView:(UIView *)view{
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}2. UIImage -> NSData
NSData *data = UIImagePNGRepresentation(image);3. NSDictionary <-> NSData
NSDictionary *dic = @{@"name":@"macRong",@"webHome":@"eqi.cc"};
NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil];
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
本文介绍如何将UIView转换为UIImage,UIImage保存为NSData的方法,并演示了如何使用NSJSONSerialization进行NSDictionary与NSData之间的互相转换。
543

被折叠的 条评论
为什么被折叠?



