当按下按钮时,它应该拍摄当前图像,并将其替换为字符串“finalurl”中的URL中的图像
它会拍摄当前图像并让它消失。它不会替换任何其他图像。我已经被困在这几天了,我很难过。任何帮助表示赞赏。
这是我使用的代码。
public void firstbutton(View view)
{
Context context = view.getContext();
Drawable image = ImageOperations(context, "@string/finalurl","image.jpg");
ImageView icon = new ImageView(context);
icon = (ImageView)findViewById(R.id.imageView);
icon.setImageDrawable(image);
};
private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
try {
InputStream is = (InputStream) this.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 Object fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
答案 0 :(得分:0)
试试这个。
Drawable drawable = LoadImageFromWebOperations(ImageLink);
imageView.setImageDrawable(drawable);
private Drawable LoadImageFromWebOperations(String url)
{
try{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}