如何在图像视图中加载验证码图像? (热链接验证码)

时间:2019-07-16 11:53:19

标签: java android imageview captcha

我正在尝试创建一个登录表单,该表单将从特定网址“ http://evarsity.srmuniv.ac.in/srmsip/”中的验证码加载到图像视图中。但是我无法做到这一点……实现这一目标的最佳方法是什么?

这是下面的Java类文件的代码:

Document document = null;
try {
    document = Jsoup.connect("http://evarsity.srmuniv.ac.in/srmsip/").ignoreContentType(true).get();
} catch (IOException e) {
    e.printStackTrace();
}
Element captchaElement = document.select("#divmain img").first();
String captchaImgSrc = captchaElement.attr("src");
InputStream inputStream = null;
try {
    inputStream = new URL("http://evarsity.srmuniv.ac.in/srmsip/" + captchaImgSrc).openStream();
} catch (IOException e) {
    e.printStackTrace();
}
Bitmap captcha = BitmapFactory.decodeStream(inputStream);
ImageView captchaImage = (ImageView) findViewById(R.id.image);
captchaImage.setImageBitmap(captcha);

图像视图崩溃或显示为nullPointer或具有白色背景,并且在代码的最后第二行中(ImageView)显示Casting是多余的。

0 个答案:

没有答案