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.
![Online-Quiz-Application-using-Firebase-Realtime-Database-Source-Code](https://learnoset.com/Learnoset/Projects/OnlineQuizApp/online_quiz_app.jpg)
Online Quiz Application using Firebase Realtime Database Source Code
![Simple-Music-Player-App-for-Android-(Offline-Version)](https://learnoset.com/Learnoset/Projects/MusicPlayer/thumnail.jpg)
Simple Music Player App for Android (Offline Version)
![QR-Code-Scanner-and-Generator-Application-for-Android](https://learnoset.com/Learnoset/Projects/QRCodeScannerAndGenerator/main_image.png)
QR Code Scanner and Generator Application for Android
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.