我有一个活动配置文件,用户可以在其中更新其个人资料图片。同时,我有一个导航抽屉,其中更新后的个人资料图片应该加载到导航抽屉的图像视图中。我需要一个代码,用户可以从代码库或照相机中选择图像并剪裁它以适应图像视图,相同的图像应该加载到主要活动中导航抽屉的图像视图中。从图库中挑选图像并将其加载到特定活动的图像视图中,并加载到另一个活动的导航抽屉imageview中
这里是我的ProfileAcitvity的代码在这段代码中,我们可以从图库中选择图像并加载到图像视图中。但是,当我们尝试返回到上一个活动并再次返回配置文件活动时,更新后的图像不存在。我们需要再次上传。
public class Profile extends AppCompatActivity {
ImageView picture;
private int PICK_IMAGE_REQUEST = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
picture = (ImageView)findViewById(R.id.picture);
picture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(getApplicationContext(),"image clicked",Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
myPrefsEdit.putString("url", uri.toString());
myPrefsEdit.commit();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
// Log.d(TAG, String.valueOf(bitmap));
picture.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
这是抽屉式导航栏图像 http://i.stack.imgur.com/JTLd3.jpg
在此先感谢
图像仅在回到主要活动后在配置文件活动图像视图中更新。我们上传新图片时如何更新图片视图。 – vishnumm93
我知道我已经阅读过你的问题。阅读我的回答 –
你上传图像到服务器? –