Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

选择了原图,图片压缩问题——不会直接返回原图 #427

Closed
wangqianjun opened this issue Apr 11, 2017 · 10 comments
Closed

Comments

@wangqianjun
Copy link

选择【原图】和不选择原图上传的图片是一样的,而且选择的图片大小有2M。是不是【原图】按钮没起作用?

@WLZJ
Copy link

WLZJ commented Apr 12, 2017

同上,设置photoWidth大于828,好像也不起作用!最后只能自己去取原图,但不知道会不会有问题?

  • (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
    for (PHAsset *asset in assets) {
    [[TZImageManager manager] getOriginalPhotoWithAsset:asset newCompletion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
    if (isDegraded) {
    //原图
    }
    }];
    }
    // 打印图片名字
    [self printAssetsName:assets];
    }

@WLZJ
Copy link

WLZJ commented Apr 12, 2017

跟一下源码,好像isSelectOriginalPhoto就是传真属性,后续操作,要我们自己写!

@banchichen
Copy link
Owner

你好,请参考这个issue:#457

@banchichen banchichen changed the title 图片压缩问题 选择了原图,图片压缩问题——不会直接返回原图 Jun 3, 2017
@jiangsihao
Copy link

您好!请问 [[TZImageManager manager] getOriginalPhotoWithAsset:assets.firstObject completion:^(UIImage *photo, NSDictionary *info) {
NSData *data = UIImagePNGRepresentation(photo);
}];
这个方法里面取得photo的大小为什么不准确,您上面原图标的是2.4MB,我通过这个方法获取的是data 是 16.2MB,好奇怪。

@banchichen
Copy link
Owner

@jiangsihao 因为你做了一次PNG无损压缩,试试用UIImageJPEGRepresentation来压缩,数据应该就比较正常了

@fryindancy
Copy link

fryindancy commented Mar 14, 2018

[[TZImageManager manager] getOriginalPhotoWithAsset:assets.firstObject completion:^(UIImage *photo, NSDictionary *info) {
      NSData *data = UIImagePNGRepresentation(photo);
      NSData *imageData = UIImageJPEGRepresentation(photo, 1.0);
}];

上面确实是有问题,如果直接用系统的处理是正常的

[[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
       float mSize =  imageData.length/1024.00/1024.00; // 单位MB ,这个才正常
}];   

@banchichen
Copy link
Owner

@fryindancy 恩,TZImageManager中的getOriginalPhotoDataWithAsset方法是走的PHImageManager requestImageDataForAsset

@jiangsihao
Copy link

我选择照片的时候 选中了原图 大小为2.1MB 但是通过UIImageJPEGRepresentation 获取原图以后 发现照片大小有5.9MB 很费解。。。 为什么上面标识的原图大小不真实。。。

@banchichen
Copy link
Owner

banchichen commented Mar 20, 2018

@jiangsihao 用UIImageJPEGRepresentation得到5.9,你传的质量系数是1.0吧...你系数变得到的图片大小就在变。

显示的2.1M,是通过下面这个系统方法获取的

[[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
       float mSize =  imageData.length/1024.00/1024.00; 
}];  

上面也提到过,如果要获取2.1M的UIImage对象,用TZImageManager中的getOriginalPhotoDataWithAsset就行。

@jiangsihao
Copy link

解决了 谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants