Picasso.with(context).load("url").into(imageView);
Here instead of url i want bitmap how can i achieve this. like below-
Picasso.with(context).load(bitmap).into(imageView);
Picasso.with(context).load("url").into(imageView);
Here instead of url i want bitmap how can i achieve this. like below-
Picasso.with(context).load(bitmap).into(imageView);
This should work for you. Use the returned URI with Picasso.
(taken from: is there away to get uri of bitmap with out save it to sdcard?)
public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
My Kotlin solution
create the 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 don't need to store the image you can avoid Picasso and load the image right away
imageView.setImageBitmap(bitmap)
otherwise store the file and load it with 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)
private void loadBitmapByPicasso(Context pContext, Bitmap pBitmap, ImageView pImageView) {
try {
Uri uri = Uri.fromFile(File.createTempFile("temp_file_name", ".jpg", pContext.getCacheDir()));
OutputStream outputStream = pContext.getContentResolver().openOutputStream(uri);
pBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.close();
Picasso.get().load(uri).into(pImageView);
} catch (Exception e) {
Log.e("LoadBitmapByPicasso", e.getMessage());
}
}
If you have bitmap, then no need to load using picasso, there is simple solution provided by android, you can use below code
imageView.setImageBitmap(bimap);
You are using an old version of Picasso.
Update the version in your Gradle file:
implementation 'com.squareup.picasso:picasso:2.71828'
Java:
Picasso.get().load(R.drawable.landing_screen).into(imageView1);
Picasso.get().load("file:///android_asset/DvpvklR.png").into(imageView2);
Picasso.get().load(new File(...)).into(imageView3);