参考: 改变图片的size,还有contentSize : http://stackoverflow.com/questions/4394491/how-to-compress-resize-image-on-iphone-os-sdk-before-uploading-to-a-server/4469273#4469273
从网络上搞下来的图片在retina屏幕设备都是比原始大小大二倍. 解决方案:看上面链接(思想:在内存中,指定大小重新渲染,排除scale的影响)
not retina:
(lldb) print dataLength
(NSUInteger) $0 = 474061
(lldb) print self.picImgView.image
(UIImage *) $1 = 0x14479c20
(lldb) print self.picImgView.image
(UIImage *) $2 = 0x14479c20
(lldb) print self.picImgView.image.size
(CGSize) $3 = (width=720, height=964)
(lldb) print self.picImgView.image.scale
(CGFloat) $4 = 1
retina:
(lldb) print dataLength
(NSUInteger) $0 = 1978691
(lldb) print self.picImgView.image
(UIImage *) $1 = 0x0cd46a60
(lldb) print self.picImgView.image.size
(CGSize) $2 = (width=720, height=964)
(lldb) print self.picImgView.image.scale
(CGFloat) $3 = 2
本地图片:
UIImage *image = [UIImage imageNamed:@"1.jpg"];
NSData *data = UIImageJPEGRepresentation(image, 1);
NSUInteger length = [data length];
NSLog(@"%d",length);
非retina:
(lldb) print image.size
(CGSize) $0 = (width=720, height=1282)
(lldb) print image.scale
(CGFloat) $1 = 1
2013-06-18 15:14:42.899 ImageSize[3933:c07] 673763
(lldb) print length
(NSUInteger) $2 = 673763
retina:
(lldb) print image.size
(CGSize) $0 = (width=720, height=1282)
(lldb) print image.scale
(CGFloat) $1 = 1
(lldb) print length
(NSUInteger) $2 = 673763
将图片名字改为后缀为@2x后打印图片
(lldb) print length
(NSUInteger) $0 = 673763
(lldb) print image.scale
(CGFloat) $1 = 2
(lldb) print image.size
(CGSize) $2 = (width=360, height=641)