Objective-c - Memory is too large when converting UIimage to NSData
巴扎黑
巴扎黑 2017-05-02 09:28:12
0
1
577

If you transfer to NSData without damaging the image quality, if the image is very large, if it is in the main thread, the memory will increase and the UI will be stuck. If it is in the sub-thread, the UI will not be stuck. But the memory will also be very large. How to solve it? (Note: The test picture, the transferred data.length is about 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