gpt4 book ai didi

java - 我无法在我的应用程序上显示下载的图像

转载 作者:行者123 更新时间:2023-12-01 18:15:43 25 4
gpt4 key购买 nike

在更新状态方法中:

public void updateStatus() {

Random random = new Random();
URLSize = celebURLs.size();

if (URLSize <= 0) {
URLSize++;
//chosenImage = random.nextInt(URLSize);
} else {
chosenImage = random.nextInt(URLSize);
}

ImageDownloader imageDownloader = new ImageDownloader();
Bitmap celebPics;

try {
celebPics = imageDownloader.execute(celebURLs.get(chosenImage)).get();
imageView.setImageBitmap(celebPics);

locationOfCorrectAnswer = random.nextInt(4);
int incorrectAnswer;
for (int i = 0; i < 4; i++) {
if (i == locationOfCorrectAnswer) {
answers[i] = chosenNames.get(chosenImage);
} else {
incorrectAnswer = random.nextInt(celebURLs.size());
while (incorrectAnswer == chosenImage) {
incorrectAnswer = random.nextInt(celebURLs.size());
}
answers[i] = chosenNames.get(incorrectAnswer);
}

}
button1.setText(String.format("%s", answers[0]));
button2.setText(String.format("%s", answers[1]));
button3.setText(String.format("%s", answers[2]));
button4.setText(String.format("%s", answers[3]));

} catch (Exception e) {
e.printStackTrace();
}

}

我更改了代码,因为它引发了异常“IllegealArgumentException n 必须为正”,但即使在更改代码以始终增加数组列表的随机生成值的大小之后,它仍然无法工作

最佳答案

所以 asynctask 实例输出一串数据,然后您将其作为 Bitmap 并希望将其设置为 Imageview 的源?那是不对的。

首先将数据放入字节数组中(这将是 asynctask 类的输出)。然后将其转为Bitmap:

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(Bitmap.createScaledBitmap(bmp, image.getWidth(),
image.getHeight(), false));

关于java - 我无法在我的应用程序上显示下载的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60374245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com