【发布时间】:2017-01-06 06:20:16
【问题描述】:
我制作了一个Activity,其中用户从图库中选择图像并将此图像设置为循环ImageView,
这是我的部分代码:
public void loadImagefromGallery(View view) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); //camera intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
Uri pickedImage = data.getData();
// Let's read picked image path using content resolver
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
cursor.moveToFirst();
String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
cursor.close();
Bitmap bitmap = BitmapFactory.decodeFile(imagePath, options);
// imgView = (de.hdodenhof.circleimageview.CircleImageView) findViewById(R.id.ivprofileimg);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] byteArrayImage = baos.toByteArray();
encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
new saveprofileimage().execute(custid, encodedImage);
} else {
Toast.makeText(this, "You haven't picked Image",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}
class saveprofileimage extends AsyncTask<String, Void, Void> {
@Override
protected void onPreExecute() {
pdilog = new ProgressDialog(MyProfile.this);
// pdilog.setMessage("Please Wait....");
pdilog.show();
super.onPreExecute();
}
@Override
protected Void doInBackground(String... params) {
try {
response = SaveProfileImage.getJSONfromURL(params[0] + " ", params[1]);
JSONObject _jobject = new JSONObject(response);
serverresult = _jobject.getString("Result");
profileimagee = _jobject.getString("ProfileImage");
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
pdilog.dismiss();
if (serverresult.equals("Success")) {
Picasso.with(MyProfile.this)
.load(profileimagee)
.into(imgView);
new customerprofiledetails().execute(custid);
} else {
Toast.makeText(MyProfile.this, "Image couldn't be saved", Toast.LENGTH_LONG).show();
}
super.onPostExecute(result);
}
}
问题是当图像已经存在于ImageView 之后,我尝试更新图像,图像没有得到更新,但是当用户关闭并重新打开应用程序时,更新的图像就在那里ImageView,
我想要的是每当我点击ImageView并选择一张图片,它会在几秒钟内当场更新,应该不需要再次打开应用程序,尽快建议我
【问题讨论】:
-
清除毕加索的缓存,然后再试一次
标签: android android-imageview android-bitmap