Best way to store images in database

Asked

Viewed 600 times

3

I have an android application that uses a mysql database, to store my users' profile information, but I would like to know the best way to store each user’s photos, because I thought to upload the imgs when it took and saved only the url, but isn’t this upload and download of imgs every time I go to open a user’s profile very expensive? If I’m going to do a listview with photos of multiple people if I download all of them I’m spending a lot right? If this is the ideal solution, I believe that somehow I must decrease the size of the image before uploading, because there are mobile phones with high resolution that save the imgs with more than megas.

  • 2

    Take this question: http://answall.com/q/12687/7261

1 answer

2


You can use the library Universal Image Loader for Android she works exactly on these issues of loading image url in listview or gridview. You can still do processing to render the image size.

Example:

// DON'T COPY THIS CODE TO YOUR PROJECT! This is just example of ALL options using.
// See the sample project how to use ImageLoader correctly.
File cacheDir = StorageUtils.getCacheDirectory(context);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
        .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
        .diskCacheExtraOptions(480, 800, null)
        .taskExecutor(...)
        .taskExecutorForCachedImages(...)
        .threadPoolSize(3) // default
        .threadPriority(Thread.NORM_PRIORITY - 1) // default
        .tasksProcessingOrder(QueueProcessingType.FIFO) // default
        .denyCacheImageMultipleSizesInMemory()
        .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
        .memoryCacheSize(2 * 1024 * 1024)
        .memoryCacheSizePercentage(13) // default
        .diskCache(new UnlimitedDiscCache(cacheDir)) // default
        .diskCacheSize(50 * 1024 * 1024)
        .diskCacheFileCount(100)
        .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
        .imageDownloader(new BaseImageDownloader(context)) // default
        .imageDecoder(new BaseImageDecoder()) // default
        .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
        .writeDebugLogs()
        .build();

Simple

String imageUri = "http://site.com/image.png"; // from Web
String imageUri = "file:///mnt/sdcard/image.png"; // from SD card
String imageUri = "content://media/external/audio/albumart/13"; // from content provider
String imageUri = "assets://image.png"; // from assets
String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)


// Load image, decode it to Bitmap and display Bitmap in ImageView (or any other view 
//  which implements ImageAware interface)
imageLoader.displayImage(imageUri, imageView);
// Load image, decode it to Bitmap and return Bitmap to callback
imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() {
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        // Do whatever you want with Bitmap
    }
});
  • Very good, then the best option would be even I upload the imgs and save only url, another thing that is missing is how I could render the image size before uploading it in the hosting.

  • On the server you leave it full (if you need quality in the image), hence, you treat it with that library already in the code. type... ImageSize targetSize = new ImageSize(50, 50); http://stackoverflow.com/questions/17136183/universal-image-loader-did-not-apply-the-displayimageoptions-in-loadimage

Browser other questions tagged

You are not signed in. Login or sign up in order to post.