0

i want to add .jpg extension to the images being saved using universal image loader but it seems we can't use "." in the name of files .

  public class UrlFileNameGenerator implements FileNameGenerator {

@Override
public String generate(String url) {

    return  new Md5FileNameGenerator().Generate(url) + ".jpg";

}

}

FATAL EXCEPTION: uil-pool-d-3-thread-1
Process: com.example.internetwallpaper, PID: 24567
java.lang.IllegalArgumentException: keys must match regex [a-z0-9_-]    {1,64}: "1828294.jpg"
at     com.nostra13.universalimageloader.cache.disc.impl.ext.DiskLruCache.valida     teKey(DiskLruCache.java:697)
at     com.nostra13.universalimageloader.cache.disc.impl.ext.DiskLruCache.get(Di    skLruCache.java:414)
at     com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiscCache.get(Lr    uDiscCache.java:133)
at     com.nostra13.universalimageloader.core.ImageLoaderEngine$1.run(ImageLoade    rEngine.java:72)
at     java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java    :1112)
at     java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.jav     a:587)
 at java.lang.Thread.run(Thread.java:841)

how to save images with .jpg extensions through universal image loader . Any help would be much appreciated , much thanks .

Ankur Teotia
  • 227
  • 1
  • 10

1 Answers1

0

Its quit long to hand with Universal Image Loader,

So I think you don't need to specify image type with file name as its not work like it, to save images as jpg format, You have to call setCompressFormat(Bitmap.CompressFormat.JPEG) to LruDiskCache. And remove file type from file url. By default every image would be save as PNG type only, as from LruDiskCache class DEFAULT_COMPRESS_FORMAT = Bitmap.CompressFormat.PNG

user370305
  • 108,599
  • 23
  • 164
  • 151
  • thanks for your reply , but this help me save my files with appropriate extensions so that i can open my files through default android image browser or the gallery app . I need my images to stored with appropriate extension . i don't want to create an in app imageview to handle images , but rather android's imageviewer to do this for me . Thats why i need my images to be saved with approproate extension . Much thanks . – Ankur Teotia Apr 30 '15 at 06:32
  • @Ankur Teotia - Just changed extension in file name doesn't mean your file is saved on that format only, extension is only as name uri for file. On your case if you don't give extension in file name and save image as `JPEG` format than also your all files has `.jpg` extension. Universal Image Loader will take care of it. – user370305 Apr 30 '15 at 13:20