|
|
#1 |
|
caching UIImage
Hi Forum,
I currently have a NSData object from a URL. The code is as follows: Code:
NSData *data = [[NSData alloc] initWithContentsOfURL: ImageURL]; Code:
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag now this image is a JPEG...so what is the difference between the following. Code:
NSData *data = [[NSData alloc] initWithContentsOfURL: ImageURL]; [data writeToFile: uniquePath atomically: YES]; Code:
NSData *data = [[NSData alloc] initWithContentsOfURL: ImageURL]; UIImage *image = [[UIImage alloc] initWithData: data]; [UIImageJPEGRepresentation(image, 100) writeToFile: uniquePath atomically: YES]; UIImage *image, CGFloat compressionQuality ); returns?? |
|
|
|
0
|
|
|
#2 |
|
Use NSData's isEqualToData: to test what you read from the url and what gets returned from the UIImageJPEGRepresentation function.
__________________
My App: CameraTime - Time lapse photography for novice and advanced users.
|
|
|
|
0
|
|
|
#3 |
|
yes they are different...but which one is correct?
|
|
|
|
0
|
|
|
#4 |
|
Try displaying both of them.
|
|
|
|
0
|
|
|
#5 |
|
like writing them back to NSdata and making a UIImage out of them?
|
|
|
|
0
|
|
|
#6 |
|
Do you want to make sure to save/cache the image exactly as it appears on the web? If so, use the first one.
If you want to convert everything to JPG (which may involve re-compressing the image, which can degrade quality), then use the second one. I'm guessing you probably want the first. |
|
|
|
0
|
|
|
#7 |
|
You could use the AsyncImageView from NickLockWood which does all of this for you + it's async..
__________________
CSS (Counter Strike Source) Tribute - iPad application ![]() iPad Mini, iPad 4, iPad 2, iPhone 3G,4,5, iMac 24", Mac Mini Last gen, Macbook Pro with Dell U2711
|
|
|
|
0
|
|
|
#8 |
|
There's also SDWebImage for async loading / caching.
__________________
|
|
|
|
0
|
|
|
#9 | ||
|
Quote:
Reasons thanks for you reply... i noticed the following: the first method creates a file which is 767KB (same size at the jpeg file ). the second method creates a file which is about 2.7 MB. The original file is a JPEG. So now it leaves me confused as to why the second method creates a files thats bigger. But yes to answer your question I want the file exactly how it appeared in my UIImageView ---------- Quote:
|
|||
|
|
0
|
|
|
#10 |
|
The async only applies to the loading and not the caching. Doesn't really make sense it that context. Anyways, asynchronous loading means that the main thread (which is where all UI is handled) is not blocked and therefore the image can be loaded "in the background". Therefore, the UX is never hung-up waiting for an image to load for a remote source.
__________________
|
|
|
|
0
|
|
|
#11 |
|
It's a well known property of jpeg image files that if you compress them repeatedly each time the image data will change. Also, if you have a jpeg that's been saved at say 40% and then you take that image and save it at 100% the new file will be larger although it will probably look the same as the 40% version.
There's no reason to re-compress a jpeg to a higher % compression. And if you want it to remain the same then don't change it at all. |
|
|
|
0
|
|
|
#12 | |
|
Quote:
|
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 05:18 AM.








Linear Mode
