My kotlin solution
create bitmap from data
val inputStream = getContentResolver().openInputStream(data.data) val bitmap = BitmapFactory.decodeStream(inputStream) val stream = ByteArrayOutputStream() bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream)
IMPORTANT: if you do not need to store the image, you can avoid Picasso and upload the image immediately
imageView.setImageBitmap(bitmap)
otherwise save the file and upload it using Picasso
val jpegData = stream.toByteArray() val file = File(cacheDir, "filename.jpg") file.createNewFile() val fileOS = FileOutputStream(file) fileOS.write(jpegData) fileOS.flush() fileOS.close() Picasso.get().load(Uri.parse(file.path)).into(imageView)
source share