Closed ghost closed 12 years ago
Hmm, good point. I think that it is generally more efficient to save the converted file, but I can see some cases where keeping the original would be desirable. I would not be opposed to having an option to saving the original images to cache, but I need to ponder a bit as how best to introduce this feature while still supporting the old behavior.
Upon further thought, I'm not sure that this is a good idea. The Bitmap.compress()
call can save images in lossless format so there is no loss of quality, as WebImage does (ie, PNG format with 100% quality). Although there might be a bit of processing overhead in converting before writing the image to disk, there is also more overhead associated in manually downloading the image bytes by hand to save them.
An advantage of the current architecture is that all image loading and saving is done through higher-level calls in the Android SDK instead of direct byte manipulation. This reduces the complexity of the library, and also lowers the chance of running into dreaded java.lang.OutOfMemory
exceptions. Also, converting raw bytes in the memory cache to a usable Drawable
object is probably going to be more CPU intensive than just passing a SoftReference
to the caller.
Finally, storing the image in memory first allows for the possibility of asynchronously writing to disk in a low-priority asynchronous task. Although WebImage doesn't do that now, it is a feature which I will probably add in the future.
It seems that the main argument here for saving first is performance, both in terms of fetching from the memory cache and in converting formats when saving images. Currently I'm not convinced that changing the existing architecture would provide much of a performance gain in this regard, but if you can write a benchmark to prove me wrong, I'd be happy to reopen this issue. :)
Would it be better if this library would save the downloaded first to the cache-directory? Because now it is being compressed to png after download.
In my opinion, this should be a better way: