Download image and use Zoom library - android

I have an activity that I'm going to display an image and I need to zoom in on it, so I found this lib
https://github.com/davemorrissey/subsampling-scale-image-view
But my picture comes from a URL I'm using Volley.
How could I use this zoom lib by downloading the image?
Intent callIntent = getIntent();
Bundle callBundle = callIntent.getBundleExtra("package");
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(R.id.imageView);
//imageView.setImage(ImageSource.resource(R.drawable.monkey));
GlideApp.with(this).load(callBundle.getString("img")).into(imageView);
Glide does not fill the object "SubsamplingScaleImageView"

I know your question pertains to Volley but you didn't mention that it was a strict requirement. You could use Fresco image library developer by facebook and at that repo they have an example of a Zoomable Image View:
https://github.com/facebook/fresco/blob/master/samples/zoomable/src/main/java/com/facebook/samples/zoomable/ZoomableDraweeView.java

Related

How to load Image and other content in UI from server

Taking example of viewpager or recyclerview in android we know that they can contain images as well.What i want to know is that how we can load images from database from server and put that images in view pager or recycler view.Upto know my understanding is that i have to make a database in server and put images in it ,now during splash screen download that images and after that put that images into view.Am i going right? Basically what i want to achieve is like shopping app which shows images which changes time to time ? how i can do same ?Do i should go with Rest API to download that images from server and then put in view also do i need to make sure that every time user opens app then it download image?
You can simply fetch .jpg URL from API and then load that image in your app by using Fresco library.
Check this out: Display images with Fresco
First add Fresco to your dependencies in app/build.gradle.
dependencies {
implementation 'com.facebook.fresco:fresco:1.10.0'
}
Don't forget to add in your AndroidManifest.xml proper permission:
<uses-permission android:name="android.permission.INTERNET"/>
Initialize Fresco in class that extend Application class. You can do it in Activity, but it's better to do it just once in Application class.
Fresco.initialize(context);
Instead of ImageView use SimpleDraweeView like this:
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/sdvImage"
android:layout_width="130dp"
android:layout_height="130dp"
fresco:placeholderImage="#drawable/myPlaceholderImage" />
Then just init your SimpleDraweeView object in Activity/ViewHolder/Fragment, parse Url string to Uri like this:
Uri imageUri = Uri.parse("https://i.imgur.com/tGbaZCY.jpg");
And you can set Uri to your SimpelDraweeView object this way:
draweeView.setImageURI(imageUri);
You can use Glide or Picasso as well. Find one that suit your needs by read this post:
Picasso v/s Imageloader v/s Fresco vs Glide

show google drive image with glide in android imageview

My drive url is -
https://drive.google.com/file/d/0B3DFHb2-MdGYa2NMUkVtVkZ1V1k/view?usp=sharing
I want to show it in android imageview using glide. I have tried many ways to show it.
Following is my code to show -
Glide.with(getActivity()).load(readExcelFeed.getImage().toString()).into(ivQueImage);
Please let me know what is the issue in it.
Steps for loads image from Google drive into ImageView by Glide Library
Step 1 : In your Drive which image you want to display on ImageView. You need to get shareable link from the three dots from the google drive. like this "https://drive.google.com/open?id=139jBj_GUfmFi_pZN38SS9RMB5wNXMEy9"
Step 2: Then the base url for display the image. link is
public static String BASE_URL = "https://drive.google.com/uc?id=";
Step 3 : In the Step 1 you see the id of the image then add this id in the base URL. Like this type
"https://drive.google.com/uc?id=139jBj_GUfmFi_pZN38SS9RMB5wNXMEy9"
Step 4 : Use Glide library for display the image on ImageView Like this:
Glide.with(mContext)
.load("https://drive.google.com/uc?id=139jBj_GUfmFi_pZN38SS9RMB5wNXMEy9")
.into(holder.user_image);
Now you can see your image on your ImageView.
Unless I'm missing something, you want to show just that single image using Glide. Just right click on it, select "Copy image address", then use that as your url String for Glide.
String url = "https://lh3.googleusercontent.com/s6-0yxPhDS4Os7SYbP66RCNp-mDwuKr72mLJx9ekuTWYFPgXahCvj-oVatwXELyVfyZzD80YTaiYde4=w1278-h954-rw";
Glide.with(getActivity()).load(url).into(ivQueImage);
For request image source you must use executeMediaAndDownloadTo()
service.files().get(fileId).executeMediaAndDownloadTo(outputStream);
Then you can get byte[] from output stream
byte[] data = outputStream.toByteArray();
and insert it to Glid
RequestOptions options = new RequestOptions();
options.skipMemoryCache(true);
options.diskCacheStrategy(DiskCacheStrategy.NONE);
Glide
.with(this)
.load(data)
.apply(options)
.transition(DrawableTransitionOptions.withCrossFade())
.into(imageView);

android - set layout background from url

I don't think it's duplicating 'cause all the answers I've found were made several years ago. So, I load bitmap from URL and then do it this way:
currentView.setBackground(new BitmapDrawable(result));
...where "result" is Bitmap.
But "BitmapDrawable" is deprecated and it doesn't work from API 22 or 21.
Are there some other way of converting Bitmap to Drawable or loading drawable from URL instead of Bitmap?
As the documentation tells you - don't use the deprecated
new BitmapDrawable(result)
Instead use the API 18 version
new BitmapDrawable(getActivity().getResources(), result)
Assuming you're supporting API 18+, otherwise you need to handle both version depending on the runtime API.
Use Glide to load image from URL, Glide is a fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.
Glide takes care of making scrolling any list of images as smooth as possible and also receive, resize and display remote image.
For more information refer here
Add below dependencies in build.gradle:
dependencies {
compile 'com.github.bumptech.glide:glide:3.6.0'
compile 'com.android.support:support-v4:19.1.0'
}
Eg project https://github.com/chrisbanes/cheesesquare
Eg usage:
#Override
public void onCreate(Bundle savedInstanceState) {
...
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);
}
In the load method just pass the URL of the image and in into just pass the view, in you case currentview.
For your scenario:
Glide.with(this).load("http://goo.gl/gEgYUd").into(currentView);

How to display a streetview preview

I have included a StreetViewPanoramaFragment in my app, but I also want to show a preview of the streetview as seen in the google maps app.
How can I achieve this?
You can load the street view image by using the Google Street View Image API.
You can specify location and image size etc in the image request URL.
private static String imageURL = "https://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,-73.988354&fov=90&heading=235&pitch=10";
For requesting image, You can use Square's Picasso library:
Picasso.with(this).load(imageURL).into(imageView);
Or use Google's Volley library:
// Get the ImageLoader through your singleton class.
mImageLoader = MySingleton.getInstance(this).getImageLoader();
mImageLoader.get(imageURL, ImageLoader.getImageListener(mImageView,
R.drawable.def_image, R.drawable.err_image));
Or use bitmap with stream:
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
imageView.setImageBitmap(bitmap);
You can also check out this answer about how to get street view image with XML.

Set ImageView through Uri

I am developing Android Web app using restfull web Services.I have written Image in my system as jpg file .Now i need to set Image into ImageView.So I have tried like this
ImageView hotelLogo;
hotelLogo = (ImageView) findViewById(R.id.imgViewHotelLogo);
hotelLogo.setImageURI(Uri.parse("D:/images/Image0800.jpg"));
but it doesn't show image in my ImageView.anyone can correct my code?
Use glide or picaso library to load image from server in both also you can load local image

Categories

Resources