objective-c - UIimage转NSData时候内存过大
巴扎黑
巴扎黑 2017-05-02 09:28:12
0
1
472

如果在不损害图片质量的情况下,转NSData,图片很大的情况下,如果是在主线程,会造成内存增大并且卡UI,如果是在子线程里,不会卡UI,但是内存同样会非常大.怎么解决呢?(注:测试图片,转出来data.length大约20M)

巴扎黑
巴扎黑

reply all(1)
phpcn_u1582

Unable to solve, converting to NSData is similar to a decompression operation and cannot reduce memory usage.

If you need to send it to the server, it is recommended to use the method shown in the picture below.

NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://example.com/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileURL:[NSURL fileURLWithPath:@"file://path/to/image.jpg"] name:@"file" fileName:@"filename.jpg" mimeType:@"image/jpeg" error:nil];
    } error:nil];
    
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!