Using image from street view - android

I want to get a picture of streetview (stating latitude and longitude) and display in a dialog, is this possible?
I saw some examples here, but not found one that show me how to display the image in dialog.
Sorry if already exists this question in the site, but I not found when I search.

Yes you can,
as a URL root you can use this one http://cbk0.google.com/ or maps.google.com
and this is a example where you use above mentioned URL by providing location:
http://cbk0.google.com/cbk?output=xml&hl=x-local&ll=34.058593,-118.240673&it=all
The result should be:
<panorama>
<data_properties image_width="13312" image_height="6656" tile_width="512" tile_height="512" pano_id="70o9Pukc2KSjO-PfeHussw" scene="1" imagery_type="2" level_id="ffffffffb3840000" num_zoom_levels="5" lat="34.058620" lng="-118.240693" original_lat="34.058620" original_lng="-118.240693" best_view_direction_deg="109.819">
<copyright>© 2013 Google</copyright>
<text/>
<street_range/>
<region/>
<country/>
</data_properties>
<projection_properties projection_type="spherical" pano_yaw_deg="93.25" tilt_yaw_deg="-180" tilt_pitch_deg="0"/>
<annotation_properties>
<link yaw_deg="252.58" pano_id="qciD6ogWmkxiq4p3OaprjA" road_argb="0x80fdf872" scene="1">
<link_text/>
</link>
<link yaw_deg="38.52" pano_id="lqiWuIrIXa_86In3RRxB1w" road_argb="0x80fdf872" scene="1">
<link_text/>
</link>
</annotation_properties>
<levels>
<level level_id="ffffffffb3840000" pano_id="70o9Pukc2KSjO-PfeHussw" ordinal="0">
<text/>
<abbreviation/>
</level>
</levels>
</panorama>
From XML you fetch pano_id, (in my case pano_id="70o9Pukc2KSjO-PfeHussw")
and after you can extract image based on pano_id:
http://cbk0.google.com/cbk?output=tile&panoid=70o9Pukc2KSjO-PfeHussw&zoom=3&x=5&y=1
Other way to get XML from maps.google.com:
http://maps.google.com/cbk?output=xml&ll=32.051626,34.7613
to load Image from URL, there is a lot options:
Drawable
public static Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
or to Bitmap:
try {
ImageView i = (ImageView)findViewById(R.id.image);
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
i.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Hope it will help you,

Related

I am facing java.net.MalformedURLException: no protocol: While converting url to bitmap in android

I am trying to convert url to bitmap and then set that bitmap to background as wallpaper. And all this process is getting done in background with the use of worker class in android. But I am getting no protocol error. I am fetching any one random wallpaper link from firebase then I am trying to convert it into bitmap by
try {
URL url = new URL(image_url);
Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
myWallpaperManager.setBitmap(image,null,false,WallpaperManager.FLAG_SYSTEM);
} catch(IOException e) {
Log.e("tag102",e.getMessage());
}
But this method gave me this error in logcat
2022-07-08 03:15:07.544 25513-25752/com.nightowl.stylo E/tag102: no protocol:
But when I put hardcoded string (showed in below method) in url method parameter then it return bitmap without any error. and wallpaper also gets changed
try {
URL url = new URL("https://images.pexels.com/photos/6336035/pexels-photo-6336035.jpeg?auto=compress&cs=tinysrgb&fit=crop&h=1200&w=800");
Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
myWallpaperManager.setBitmap(image,null,false,WallpaperManager.FLAG_SYSTEM);
} catch(IOException e) {
Log.e("tag102",e.getMessage());
}
But i want random string to set and get me bitmap from that. So how i can achieve that? I also try to encode url by
try {
encodedURL = URLEncoder.encode(image_url, "UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e("tag3",e.toString());
}
I am using three kind of url in this project
https://images.pexels.com/photos/6336035/pexels-photo-6336035.jpeg?auto=compress&cs=tinysrgb&fit=crop&h=1200&w=800
https://cdn.pixabay.com/photo/2020/11/27/22/07/naruto-5783102_960_720.png
https://images.unsplash.com/photo-1641414315243-196e7382c32d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1178&q=80
Any help will be appreciated.

Set a Parsed (JSON) image into background of a layout? [duplicate]

This question already has answers here:
Android - How to download an image and use it as new resource?
(4 answers)
Closed 9 years ago.
I have got a demo image link :
http://madhabpurps.org/wp-content/uploads/2013/04/28-239x300.jpg
I want to set the image in the background of a layout inside the view holder class:
static class ViewHolder {
TextView txtName;
TextView txtCityState;
RelativeLayout rl;
}
holder.txtName.setText(searchArrayList.get(position).getTitle());
holder.txtCityState.setText(searchArrayList.get(position).getDescription());
I have to set the image from the link here, I have tried this line of code but it's showing error.
holder.rl.setBackgroundResource(searchArrayList.get(position).getImage());
I get answer from here change background image of Framelayout via URL
private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
try {
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, saveFilename);
return d;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public Object fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
and then you can use it like this
Drawable drw = ImageOperations(this,url,filename)
rl.setBackgroundDrawable(drw);
This should fix. But for general case I recommend another way to solve these problems.
I recommend using a well documented image downloading and caching library. I am using picasso http://square.github.io/picasso/ . Setup it, using library is easy.
Then you can fill an imageview by just writing
Picasso.with(activity)
.load(url)
.fit()
.into(imageView);
use the below code
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent());
Drawable d = new BitmapDrawable(getResources(),bitmap);
rl.setBackgroundDrawable(dr);

Unable to clear or set blank image in imageview in android

if(bigimageS.length()==0){
show_image.setImageBitmap(null);
}else{
show_image.setImageBitmap(decodeImage(bigimageS));
}
****************
public static Bitmap decodeImage(String arrayList_image) {
BufferedInputStream bis;
URL aURL;
try{
aURL = new URL(arrayList_image);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
return bm;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
this is my code and i want to clear imageview.my problem is i am getting the image in bigimages String.i am adding the imageurl from w/s.in string bigimages.when i click on next btn after once image set then old image is not clear.so plz help i put condition but not working.plz help.
I am using the decodeimage for decode the image so is it any way to clear if there is no url in string..help me plz not solve yet
create a blank /transparent png image from photoshop , and apply as your image background.
You need to check the length of the url . If it is 0 then you have to set null to imageviwe.
Please try this.
if(imageneel.get(i).length() == 0)
{
show_image.setImageBitmap(null);
}
try this one code
for (int i = 0; i < imageneel.size(); i++) {
if(imageneel.get(i).trim().length() == 0){
show_image.setImageBitmap(null);
}else{
show_image.setImageBitmap(decodeImage(imageneel.get(i)));
}
}
Agree with Pranav, but i think you can also access inbuild resources of Android itself.
Try:
imgView.setImageResource(android.R.color.transparent);
finally i got the solution..i have simply set the blank like this bigimageS="";
before getdata(); method..
It is simple as passing a 0 as the resource
show_image.SetImageResource(0);

Internet url as Android ImageSpan source

is it possible to specify internet url for ImageSpan and get it shown with TextView? I've tried quite a few versions of
String mockContent = "<img src=\"http://www.google.com/intl/en_com/images/srpr/logo3w.png\">";
myTextView.setText(Html.fromHtml(mockContent), BufferType.SPANNABLE);
but that results in the generic not found image (blueish black bordered square).
Do I have to download the image first, then replace all the urls and so on?
Knowing the new C# is capable of handling such resources, I hoped Android might meet my hopes here.
Using API version 10: 2.3.3.
If you have the image source locally then it should work or else use,
Html.fromHtml(String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler)
Returns displayable styled text from the provided HTML string.
Nice example I found on web,
String s = Html.fromHtml(htmlContent, new ImageGetter() {
#Override
public Drawable getDrawable(String source) {
// Code for getting image either by download or using static iamge
Drawable d = null;
try {
InputStream src = imageFetch(source);
d = Drawable.createFromStream(src, "src");
if(d != null){
d.setBounds(0,0,(d.getIntrinsicWidth(),
d.getIntrinsicHeight());
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return d;
}
},null);
For more info Html.fromHtml with ImageGetter.

ListView scrolling lag in android

I am having a customized list view in my application, which is showing an image and text.
The Image I am getting from URL, using the code below:
private static Drawable ImageOperations(Context ctx, String url,
String saveFilename) {
try {
InputStream is = (InputStream) fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static Object fetch(String address) throws MalformedURLException,
IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
all is working perfect, except the list view scrolling, its very slow. If I disable the images, the scroll speed smooth-ens , but with the image enabled, it lags alot.
Is there any possible way I can reduce or remove this lagging?
Thanks
You need to do your fetching in the background.
One of the examples you can use :
http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html
use this library for downloading images in background and caching..
it won't hurt the UI
https://github.com/koush/UrlImageViewHelper
Are you lazy loading your images? See this question for details.

Categories

Resources