3

There is a path to the image like this:

String path = "http://mysyte/images/artist/artist1.jpg"

I have ImageView, which is loaded a small copy of the picture. I use the side of the library Picaso:

Picasso.with(getApplicationContext()).load(path).into(imageview);

Create Event Onclick () on Imageview:

public void click_img(View v){
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);

        startActivity(intent);
    }

How to open an image in the gallery, full screen size of the gallery? Where to find a way to implement it, but there in drawable-resources, and I need that to it is through the remote path to the picture?

duddeniska
  • 153
  • 3
  • Check this post http://theopentutorials.com/tutorials/android/imageview/android-how-to-load-image-from-url-in-imageview/ – bGorle Jul 27 '15 at 16:28
  • "I have ImageView, which is loaded a small copy of the picture. I use the side of the library Picaso: Picasso.with(getApplicationContext()).load(path).into(imageview);" I get the image url in the imageView. I need to when you click on the image, it opens up the entire screen in the gallery – duddeniska Jul 27 '15 at 16:33
  • Try to get the location where picasso is storing the file, Send an `Intent` to gallery application. – bGorle Jul 27 '15 at 16:36
  • I made the following: public void click_img(View v){ Intent intent1 = new Intent(); intent1.setAction(Intent.ACTION_VIEW); Uri imgUri = Uri.parse(path_img); intent1.setDataAndType(imgUri, "image/*"); startActivity(intent1); } But I get an error: no activity foun – duddeniska Jul 27 '15 at 16:47

1 Answers1

1

The most straightforward way of doing this is to save the image to SD and then use an Intent to open the default gallery app.

Since you're already using Picasso, here's a way to do it using that lib:

private Target mTarget = new Target() {
      @Override
      public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
          // Perform simple file operation to store this bitmap to your sd card
          saveImage(bitmap);
      }

      @Override
      public void onBitmapFailed(Drawable errorDrawable) {
         // Handle image load error
      }
}

private void saveImage(Bitmap finalBitmap) {

    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/saved_images");    
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "Image-"+ n +".jpg";
    File file = new File (myDir, fname);
    if (file.exists ()) file.delete (); 
    try {
           FileOutputStream out = new FileOutputStream(file);
           finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
           out.flush();
           out.close();

    } catch (Exception e) {
           e.printStackTrace();
    }
}

Target is a class provided by Picasso. Just override the onBitmapLoaded method so that it saves your image to SD. I provided a sample method for saveImage for you. See this answer for more info.

You'll also need to add this permission to your Manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
Community
  • 1
  • 1
adao7000
  • 3,632
  • 2
  • 28
  • 37
  • How to open an image in the gallery, full screen size of the gallery? I dont see event onclick on image – duddeniska Jul 27 '15 at 17:06
  • Yeah, you'll still need to implement the onClickListener for your ImageView. – adao7000 Jul 27 '15 at 17:19
  • That's when you'll call your Intent (like you've already shown above using the path where you've saved your image to SD) – adao7000 Jul 27 '15 at 17:20
  • 1
    That's working without save images on SD. public void click_img(View v){ Intent intent1 = new Intent(); intent1.setAction(Intent.ACTION_VIEW); Uri imgUri = Uri.parse(path_img); intent1.setDataAndType(imgUri, "image/*"); startActivity(intent1); } – duddeniska Jul 27 '15 at 17:26