Android Studio Examples

100+ tutorials, source code, and examples to help you develop creative and technical skills.

how to convert uri to bitmap in android example

MainActivity.java

private Bitmap uriToBitmap(Uri uri){
        Bitmap bitmap = null;

        try {
            bitmap = MediaStore.Images.Media.getBitmap(getContentResolver() , uri);
        } catch (IOException exception) {
            exception.printStackTrace();
            Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
        }

        return bitmap;
    }

    private Uri convertImageViewToUri(ImageView imageView, String filename) {

        OutputStream imageOutStream;
        Uri uri = null;
        Bitmap imageBitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();

        try {

            // create path
            final String createPath = getExternalFilesDir(null).getAbsolutePath() + "/" + filename;

            imageOutStream = new FileOutputStream(createPath);

            // saving Bitmap
            imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, imageOutStream);
            imageOutStream.close(); //  close output stream

            uri = Uri.fromFile(new File(createPath));
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this, "Something went wrong!!", Toast.LENGTH_SHORT).show();
        }

        return uri;
    }

Projects with Source Code + Video Tutorials

You can download our Java and Android Studio Projects with Source Code and Video Tutorials.

Programming-Quiz-App-for-Android-(Offline-Version)
Programming Quiz App for Android (Offline Version)
Login-and-Register-screen-with-OTP-Verification-Material-UI-design
Login and Register screen with OTP Verification Material UI design
Login-and-Register-Activity-Material-UI-design-in-Android-Studio
Login and Register Activity Material UI design in Android Studio

If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com

Follow us to learn Coding and get in touch with new Technologies.