1

我想从我们的网络驱动器设置 ImageView 位图。但我无法连接到服务器:无法登录到服务器(PASS):141.11.11.247 错误。

这是我为此下载的 ant setBitmap 代码:

public class ResimCek implements Runnable {

    int resimID = 0;

    public ResimCek(int parcaID) {
        // store parameter for later user
        resimID = parcaID;
    }

    public void run() {
        try {
            ImageView resim = (ImageView) findViewById(resimID);
            Bitmap bitmap = BitmapFactory
                    .decodeStream((InputStream) new URL(
                            "file://141.11.11.247/foto_metod/Parca/"
                                    + Integer.toString(resimID) + ".jpg")
                            .getContent());
            resim.setImageBitmap(bitmap);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

这是我的最后一个代码:

public class ResimCek implements Runnable {

    int resimID = 0;

    public ResimCek(int parcaID) {
        // store parameter for later user
        resimID = parcaID;
    }

    public void run() {

        int resID = getResources().getIdentifier(Integer.toString(resimID) , "tag", getPackageName()); 
        ImageView resim = (ImageView) findViewById(resID);

        Drawable image = ImageOperations(getBaseContext(),"http://141.11.11.206/parca/" + Integer.toString(resimID) + ".jpg" ,"I" + Integer.toString(resimID) + ".jpg");
        // ******************************************************
        resim.setImageDrawable(image); // I GOT THE ERROR HERE!!!
    }
}
private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
    try {
        InputStream is = (InputStream) this.fetch(url);
        Drawable d = Drawable.createFromStream(new URL(url).openConnection().getInputStream(),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;
}

谢谢你的帮助。

4

2 回答 2

1

可能是您忘记在清单文件中声明互联网权限,请检查。

于 2012-04-18T09:09:16.093 回答
0

下载FtpClient

并使用用户名和密码登录。看看这个文档,希望对你有帮助。

于 2012-04-18T09:25:51.280 回答