简体   繁体   English

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

[英]How to set bitmap in ImageView after saved in server

I want to set bitmap in imageview after saved on the server. 保存到服务器后,我想在imageview中设置位图。 I tried a lot, it's saved in a server but not set in imageview. 我尝试了很多,它已保存在服务器中,但未在imageview中设置。 If I didn't send to the server means it fix in imageview. 如果我没有发送到服务器,则意味着它已在imageview中修复。 How to do both 两者都要做

Here my code: 这是我的代码:

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();
                }
            }
        }
  }

Thanks in advance.. 提前致谢..

first approach is : 第一种方法是:

if u dont want to wait for successful upload on the server and then load the image in the imageview then you can simple do 如果您不想等待服务器上的成功上传,然后将图像加载到imageview中,则可以简单地执行

profilePic.setImageURI(mSelectedImageUri) profilePic.setImageURI(mSelectedImageUri)

and in case you want to wait for successful upload, then u can get the imageurl as the response , and use that url with picasso library to load image into your imageView as 如果您要等待成功上传,则可以获取imageurl作为响应,并将该URL与picasso库一起使用,以将图片加载到imageView中,

Picasso.with(context) .load(url) .resize(50, 50) .centerCrop() .into(profilePic) Picasso.with(上下文).load(url).resize(50,50).centerCrop().into(profilePic)

Note :- If are selecting image from memory,make sure u have storage read permissions 注意:-如果要从内存中选择图像,请确保您具有存储读取权限

您可以将位图设置为imageview。

imageView.setImageBitmap(bitmap);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM