[TIMOB-15247] iOS: Ti.Blob.imageAsResized always returns a png image
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-04-16T18:21:32.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | iOS |
Labels | blob, image, jpeg, parity, png |
Reporter | Cedric Paternotte |
Assignee | Vishal Duggal |
Created | 2013-07-05T16:05:43.000+0000 |
Updated | 2017-03-31T22:22:06.000+0000 |
A simple test case would be nice :)
Here is a workaround that works for me on iOS : use Ti.ImageFactory.compress to force jpeg format. This workaround requires the [ImageFactory](https://marketplace.appcelerator.com/apps/4973) module ([github](https://github.com/appcelerator/titanium_modules/tree/master/imagefactory)).
This issue requires a Test Case.
Test case:
Hi, I solved this issue. The problem lies in the UIImage+Resize.m When the image is resized in the + (UIImage *)resizedImage:(CGSize)newSize transform:(CGAffineTransform)transform drawTransposed:(BOOL)transpose interpolationQuality:(CGInterpolationQuality)quality image:(UIImage*)image hires:(BOOL)hires it is always assumed that the image has an alpha channel by passing kCGImageAlphaPremultipliedLast when the bitmap context is created. The passed image has first to be checked if it has an alpha channel or not and then create the bitmap context accordingly. Long story short: replace kCGImageAlphaPremultipliedLast with [UIImageAlpha hasAlpha:image] ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipFirst at line 49 of this file. Tested and works on Ti 3.2.2.GA, iOS 7.1, simualtor iPhone 3.5''
Android seems to be returning a bitmap. "image/bitmap" mimetype. Can anything be done about this?
Thank you all. Is anyone able to file a PR based on these findings? If so, we'd be happy to merge it in.
I'm going to try out [~giorgos29cm]'s suggestion & will update my results.
For me [~lulu]'s use of *ImageFactory* has been the best option. I did not see a difference on iOS with [~giorgos29cm] modification. Someone can double check. Result on *Android* - image.imageAsResized...): 1- image Original size: undefined image Original dimensions: 3264x2448 2- image size Resize :undefined image dimensions After Resize: 853x640 3- image JPG image size: 58551 (very decent for a Camera Snapshot on a Samsung S3) On *iOS* (different Image with ImageFactory.compress(image.imageAsResized...), 0.75): 1- image Original size: 1500000 image Original dimensions: 1500x1000 2- image size Resize: 614400 image dimensions After Resize: 640x960 3- image JPG image size: 233242
Cedric's workaround has worked for me. I don't have the stats handy, but pre-workaround, resized images were around 2MB and I confirmed were PNG data in a blob otherwise identified as a JPG. Post-workaround, sizes are around 150KB w/JPG data in the blob. I have not tried Giorgos' modification.
Pull pending master - https://github.com/appcelerator/titanium_mobile/pull/6783
the PR above was merged 16 Apr, but with 4.0.0.GA I still have a png on iOS when just using imageAsResized
Closing ticket as fixed, if there are any problems, please file a new ticket.