Android Bitmap Scale getScaledImageFromUri(Activity activity, Uri uri, int size)

Here you can find the source of getScaledImageFromUri(Activity activity, Uri uri, int size)

Description

get Scaled Image From Uri

Declaration

public static Bitmap getScaledImageFromUri(Activity activity, Uri uri,
            int size) 

Method Source Code

//package com.java2s;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;

public class Main {
    public static Bitmap getScaledImageFromUri(Activity activity, Uri uri,
            int size) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = size;/*from  w w w.j  a  va2s  . c  o  m*/
        String imagePath = getRealPathFromURI(activity, uri);
        if (imagePath != null) {
            Bitmap bitmapImage = BitmapFactory.decodeFile(imagePath,
                    options);
            return bitmapImage;
        } else {
            return null;
        }
    }

    public static String getRealPathFromURI(Activity activity,
            Uri contentUri) {
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = activity.managedQuery(contentUri, proj, null, null,
                null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        if (cursor.moveToFirst()) {
            return cursor.getString(column_index);
        } else {
            return null;
        }
    }
}

Related

  1. generateScaledBitmap(byte[] bitMapData, int width, int height)
  2. crossStretchImageX(Bitmap image, int xsize)
  3. scaleBitmap(Bitmap bitmap, int width, int height)
  4. scaleBitmap(String path, int newWidth, int newHeight)
  5. scaleClipBitmapByCircle(Bitmap src, int nRadius, float fStrokeWidth)
  6. imageScale(Bitmap bitmap, int dst_w, int dst_h)
  7. scaleBitmap(Bitmap bitmap, float scale)
  8. scaleBitmapDown(Bitmap bitmap)
  9. scaleToFit(Bitmap bm, float width_Ratio, float height_Ratio)