如何从服务器检索上传的图像到Android应用程序

时间:2013-07-15 12:01:19

标签: android json

我将图像作为Base64编码方法上传到服务器,它作为字符串发送,我可以从服务器检索该字符串并解码它们

2 个答案:

答案 0 :(得分:0)

you have link for that..json parsing ,xml parsing u can get the address and then u can   implement that image in ur apps.

答案 1 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Loading image from url"
    android:layout_margin="10dip" />

<ImageView android:id="@+id/image"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_margin="10dip"/>

</LinearLayout>

public class LoadImageFromURLActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Loader image - will be shown before loading image
    int loader = R.drawable.loader;

    // Imageview to show
    ImageView image = (ImageView) findViewById(R.id.image);

    // Image url
    String image_url = "http://images4.fanpop.com/image/photos/18900000/Cute-couples-_-love-18948423-500-334.jpg";

    // ImageLoader class instance
    ImageLoader imgLoader = new ImageLoader(getApplicationContext());

    // whenever you want to load an image from url
    // call DisplayImage function
    // url - image url to load
    // loader - loader image, will be displayed before getting image
    // image - ImageView
    imgLoader.DisplayImage(image_url, loader, image);
}
}

 <!-- Internet Permissions -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- Permission to write to external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />