我想从我们的网络驱动器设置 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;
}
谢谢你的帮助。