It is necessary to save either six images on the phone’s memory or on the SD card. They are downloaded from the internet. To download using Picasso. I am trying to create a new image file through Target, and then output it. Here is the code:

Picasso.with(this).load(image_ar.get(0)).into(new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { Log.e("tag", "Picasso > onBitmapLoaded"); File file = new File(Environment.getExternalStorageDirectory().getPath() + "/name.jpg"); //путь к изображению FileOutputStream out; try { out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); out.close(); } catch (IOException e) { e.printStackTrace(); } Picasso.with(getApplicationContext()).load("file:///" + file.getPath()).into(image.get(0)); } @Override public void onBitmapFailed(Drawable errorDrawable) { Log.e("tag", "Picasso > onBitmapFailed"); } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { Log.e("tag", "Picasso > onPrepareLoad"); } }); 

But as a result, I do not get anything.

  • You have in the code on the event of loading the image in the ImageView loaded some file. There is no entry to the file in the code. And the picture downloaded from the Internet is not used anywhere - YuriySPb
  • And how can you fix this? For example, if possible, please - Jonny

1 answer 1

  1. According to the issue of Google on request

android write bitmap to file

you can write Bitmap to a file like this :

 FileOutputStream out = null; try { out = new FileOutputStream(filename); bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance // PNG is a lossless format, the compression factor (100) is ignored } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } 
  1. Then this file can be displayed via Picasso like this:
 Picasso.with(getApplicationContext()) .load("file:///" + filePath) .placeholder(R.mipmap.ic_launcher) .into(imageView); 
  • The same, the code in the question corrected - Jonny
  • @Jonny, did you create a file with a picture? Maybe you did not specify permission to write? - YurySPb
  • <uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" /> This is spelled out. The application sees the file as if, but the picture itself is not displayed. Just by default, there is already an image there, but nothing is displayed in the ImageView, therefore the image exists, it simply does not appear, or it is not loaded into the file. - Jonny
  • @Jonny, try adding a read permission. Also check if the picture is recorded in the file - YuriySPb
  • Exactly, thanks, it works.)) - Jonny