标签:style class blog code http color
//类方法 图片 转换为二进制 +(NSData *)Image_TransForm_Data:(UIImage *)image { NSData *imageData = UIImageJPEGRepresentation(image , 0.5);
//几乎是按0.5图片大小就降到原来的一半 比如这里 24KB 降到11KB return imageData; } //调用方法举例 -(void)viewWillAppear:(BOOL)animated { [self Read_ImageData]; } - (void)viewDidLoad { nav_View=[[NavView alloc]init]; [self.view addSubview: [nav_View NavView_Title:@"通告"]]; [super viewDidLoad]; [self Read_ImageData]; } //以下方法 就是把一图片压缩成二进制 再转换成图片做显示 效果 不错 -(void)Read_ImageData { UIImageView *imageView1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 80, 200, 200)]; imageView1.image=[UIImage imageNamed:@"cat_food.png"]; [self.view addSubview:imageView1]; UIImageView *imageView3=[[UIImageView alloc]initWithFrame:CGRectMake(0, 280, 200, 200)]; imageView3.image=[UIImage imageWithData:[Function Image_TransForm_Data:imageView1.image] ]; [self.view addSubview:imageView3]; NSData *data = [NSData dataWithData:[Function Image_TransForm_Data:imageView1.image ]]; [data writeToFile:[Function CreateTheFolder_From:Library_Cache FileHolderName:MyFolder FileName:@"pp111111.png"] atomically:YES]; }
效果图:如下
能看到一点被压缩质量的细节是不是 还好哈哈
IOS 图片转换二进制 二进制转换为图片,布布扣,bubuko.com
标签:style class blog code http color
原文地址:http://www.cnblogs.com/someonelikeyou/p/3799333.html