gpt4 book ai didi

java - 保存到服务器后如何在 ImageView 中设置位图

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

我想在保存到服务器后在imageview中设置位图。我尝试了很多,它保存在服务器中但未设置在imageview中。如果我没有发送到服务器意味着它在 ImageView 中修复。如何同时做到这两点

这是我的代码:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_PHOTO && data != null && resultCode == RESULT_OK ) {
Bundle extras = data.getExtras();
if(extras != null) {
bitmap = extras.getParcelable("data");
mSelectedImageUri = getImageUri(this.getApplicationContext(), bitmap);
// CALL THIS METHOD TO GET THE ACTUAL PATH
File file = new File(getRealPathFromURI(mSelectedImageUri));
profilePic.setImageBitmap(bitmap);
getContentResolver().delete(mSelectedImageUri, null, null);

JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("format", splitFormat[1]);
jsonObject.put("accId",acc_id);
jsonObject.put("encodeImage",encodeTobase64(bitmap));
input = new StringEntityHC4(jsonObject.toString());
input.setContentType("application/json");
input.setContentEncoding("UTF-8");
UpdateProfilePicToServer();
} catch (JSONException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}

提前致谢..

最佳答案

第一种方法是:

如果你不想等待服务器上成功上传然后将图像加载到imageview中那么你可以简单地做

profilePic.setImageURI(mSelectedImageUri)

如果您想等待成功上传,那么您可以获取 imageurl 作为响应,并使用该 url 与 picasso 库将图像加载到您的 imageView 中

Picasso.with(上下文) .load(网址) .调整大小(50, 50) .centerCrop() .into(个人资料图片)

注意:-如果从内存中选择图像,请确保您具有存储读取权限

关于java - 保存到服务器后如何在 ImageView 中设置位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40242017/

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