You need to use BitmapFactory class and based on below method declare you can easily convert bitmap from a string path of image , here i set 400,400 (Height and Width of image but it is not good
idea to fix height and width ) you can use option/4 , option/2 that manes it takes 1/2 or 1/4 of the height , width ratio of original image height and width
public static Bitmap decodeBitmapFromResource(String imagePath) throws OutOfMemoryError {
try {
// First decode with inJustDecodeBounds=true to check dimensions
// File sd = Environment.getExternalStorageDirectory();
File image = new File(imagePath);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(),bmOptions);
bitmap = Bitmap.createScaledBitmap(bitmap,400,400,true);
return bitmap;
} catch (Exception ex)
{
ex.printStackTrace();
}
return null;
}
No comments:
Post a Comment