How can create a bitmap image using string file path of image Android


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:

IRCTC Share Price Declines by 2% Despite 30% Jump in Q4 Net Profit; Board Announces Dividend of INR 2 per Share

Introduction: The share price of Indian Railway Catering and Tourism Corporation (IRCTC) experienced a decline of 2% in today's trading ...