Example:
Add this line in your AndroidManifest.xml file:
Layout main.xml
main.java
package com.blog.loadimage; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import android.app.Activity; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.Editable; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; public class main extends Activity { EditText imageUrl; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); imageUrl = (EditText)findViewById(R.id.editTextUrl); Button getImageButton = (Button)findViewById(R.id.buttonGetImage); getImageButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Context context = v.getContext(); Editable ed = imageUrl.getText(); Drawable image = ImageOperations(context,ed.toString(),"image.jpg"); ImageView imgView = new ImageView(context); imgView = (ImageView)findViewById(R.id.imageView); imgView.setImageDrawable(image); } }); } private Drawable ImageOperations(Context ctx, String url, String saveFilename) { try { URL imageUrl = new URL(url); InputStream is = (InputStream) imageUrl.getContent(); Drawable d = Drawable.createFromStream(is, "src"); return d; } catch (MalformedURLException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } } }
12 comentarii:
I've come across this many times now while looking for a solution to this, but I'm curious—what is the significance of the Context and saveFile parameters in the ImageOperations method? I don't see a time when they are referenced within the method, or any time where a Context is even necessary.
Why not just use a WebView?
Your code is not working for BITMAP images plz update it ...... I am finding difficulty in downloading a bitmap image ...
Really this is one of the progressive post.Thanks for collective this type of Information relate to Android.This is one of the good mobile application.We are also providing some logic related to Android.
Android app developers
it is showing run time error
i'm getting error as "unfortunately webimage(my app name) has stopped..
im get error "unfortunately" application has stopped , can anyone help me? :'(
Those getting errors, check the formatting of the main.xml, capitalisation of the tags is incorrect .. fixed it for me.
ie change to EditText, Image, ButtonView
Probably goes without saying, remove the comment tags from the XML declaration in the first line too ;)
Information which you provided on web image is excellent and useful. Thanks for this. Keep doing such work.
Description - We are the best web design company in Karachi, Pakistan offers the best web development services, SEO, SMO, android application development, LOGO Design services etc in cheap rates.
Thanks for providing great information.Its very easy to understand and helpful to me Apps Development Android
Custom Android App Development is said to have an instructing position in the Smartphone market as Android is a mind rousing stage to make Smartphone applications.
Post a Comment