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.
Related
I am using OpenStreetMap, I am able to load custom icons (multiple) from drawable using the following code:
startMarker = new Marker(map);
startMarker.setPosition(new GeoPoint(latitude,longitude));
startMarker.setAnchor(Marker.ANCHOR_CENTER, 1.0f);
startMarker.setTitle((intMarkerID+"").trim());
startMarker.setIcon(getResources().getDrawable(R.drawable.loading));
map.getOverlays().add(startMarker);
I would like to use Picasso or Glide to load marker icons from URL, I already have the URLs in a string format from an array, I just need to apply these strings url_abs_fileName ("Image URLs") as a marker icon for OpenStreetMap (Not Goolge Maps), how can I achieve that?
I need to set OSM icons to something like this (example):
if (url_abs_fileName != null) {
Picasso.with(this)
.load(url_abs_fileName)
.placeholder(R.drawable.loading)
.into((Target) startMarker);
}
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
I stored the path to my images in mysql db and was not sure if there's a way to load them in an imageView using volley library.
I'm able to parse string as json and display it in textView using volley string request queue but wasn't sure how I can get the path to display as image in my imageView. I would like to fetch the image using id.
Thanks in advance!
I always use the Glide to load images like this. Simply return the path like you do any other string. There is no need to load a bitmap with Volley, using Glide for this is simpler and better. Glide will handle for example image caching amongst other things.
This is all you need except from the Volley part.
ImageView imageView = findViewById(R.id.image);
String url = "www.foobar.com/" + path;
Glide.with(context).load(url).into(imageView);
Recently, I used Picasso library in my project and it worked fine and smooth. You can easily Load Image to ImageView from Url by using Picasso. Moreover, you can resize the original image to your desire size.
Example:
String mURL = "https:\/\/c.tribune.com.pk\/2017\/12\/1593389-vanga-1514310781-708-160x120.jpg";
ImageView Icon = (ImageView) findViewById(R.id.icon);
Picasso.with(context).load(mURL).resize(72, 72).into(icon);
Note: Using Picasso first you must import its library.
I used this: compile 'com.squareup.picasso:picasso:2.5.2'
use glide to display your image or you can use picasso
new ImageRequest(
url,
listener,
maxWidth,
maxHeight,
decodeConfig,
errorListener);
Response.Listener<Bitmap> listener = new Response.Listener<Bitmap>() {
#Override
public void onResponse(Bitmap bitmap) {
//here you set the bitmap to 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);
I have a listview, getting news thumbnail and header from json.
I want to show news body and bigger image in other activity by clicking listview item. The code below send image to other activity.
secilenresim= (ImageView)view.findViewById(R.id.mansetresim);
secilenresim.buildDrawingCache();
Bitmap image= secilenresim.getDrawingCache();
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", image);
//// the code below gets the image in new activity
haberresim=(ImageView)findViewById(R.id.haberresim);
haberresim.getLayoutParams().height = 300;
haberresim.getLayoutParams().width = 400;
Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
haberresim.setImageBitmap(bmp);
all works fine. but image quality in new activity is too bad. whereas image source (coming from json and loaded by picasso library) is fine, and the image resolution is 600*400 pixels. How can I pass image to other activity and keep quality?
If you are using picasso, your image is downloaded once and then kept in memory or even disc-cache. So you won't have to pass the bitmap via bundle but only the URL to it from your JSON.
In your Detail-Activity you can request the image via picasso again for your larger imageView.
You can check if your image is loaded from cache or network if you enable the picasso debug flag:
picasso.setDebugging(true)
getDrawingCache() may be getting image with low quality.
to change it use:
secilenresim.setDrawingCacheQuality(DRAWING_CACHE_QUALITY_HIGH);
you can check your quality with getDrawingCacheQuality(). It can be one of those:
DRAWING_CACHE_QUALITY_AUTO
DRAWING_CACHE_QUALITY_LOW
DRAWING_CACHE_QUALITY_HIGH
EDIT:
it seems that secilenresim.destroyDrawingCache(); before building it may be also helpful