gpt4 book ai didi

java - 如何在 Android 中将此图像设置为 Activity

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

我正在 Android 上使用异步下载文件,现在我希望此文件在 Activity 中显示。我如何在 onSucess 方法中执行此操作?我尝试了以下方法,但图像未显示!

AsyncHttpClient fileDownload = new AsyncHttpClient();
String[] allowedContentTypes = new String[] { "image/png", "image/jpeg" };
fileDownload.get("http://server.com/file.png", new BinaryHttpResponseHandler(allowedContentTypes) {
@Override
public void onSuccess(byte[] fileData) {
//Do Something here to view files in activity
ImageView img = (ImageView) findViewById (R.id.imageview1);
}

最佳答案

试试这个代码

AsyncHttpClient fileDownload = new AsyncHttpClient();
String[] allowedContentTypes = new String[] { "image/png", "image/jpeg" };
fileDownload.get("http://server.com/file.png", new BinaryHttpResponseHandler(allowedContentTypes) {
@Override
public void onSuccess(byte[] fileData) {
//Do Something here to view files in activity
Bitmap bmp=BitmapFactory.decodeByteArray(fileData,0,fileData.length);
ImageView img = (ImageView) findViewById (R.id.imageview1);
img.setImageBitmap(bmp);
}

关于java - 如何在 Android 中将此图像设置为 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15399177/

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