想要只存储图像一次,但图像存储3次在文件夹中所有功能只调用一次,但图像存储3次而不是一次。
private ImageChooserManager imageChooserManager;
private File mFileTemp;
这是我的setOnClickListener
LinDriverImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// showchooseImagePopup(getActivity(), "user");
final MaterialSimpleListAdapter adapter = new MaterialSimpleListAdapter(new MaterialSimpleListAdapter.Callback() {
@Override
public void onMaterialListItemSelected(MaterialDialog dialog, int index, MaterialSimpleListItem item) {
if (index == 0) {
chooseImageFromGallery();
Log.d("imagechoser", "LinDriverImage");
imageStatus = "user";
materialDialog.dismiss();
}
if (index == 1) {
chooseImageFromCamera();
imageStatus = "user";
materialDialog.dismiss();
}
}
});
adapter.add(new MaterialSimpleListItem.Builder(ActivityDriverProfile.this)
.content("Gallery Image")
.icon(R.drawable.ic_add_a_photo_black_24dp)
.backgroundColor(Color.WHITE)
.build());
adapter.add(new MaterialSimpleListItem.Builder(ActivityDriverProfile.this)
.content("Capture Image")
.icon(R.drawable.ic_camera_alt_black_24dp)
.backgroundColor(Color.WHITE)
.build());
materialDialog = new MaterialDialog.Builder(ActivityDriverProfile.this)
.title("Choose option")
.adapter(adapter, null)
.show();
}
});
我使用chooseImage选择图像
private void chooseImageFromCamera() {
imageChooserManager = new ImageChooserManager(this, ChooserType.REQUEST_CAPTURE_PICTURE, "myfolder", true);
imageChooserManager.setImageChooserListener(ActivityDriverProfile.this);
try {
imageChooserManager.choose();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
我想可能这些代码行有一些问题,但我不知道onImageChosen也只调用过一次。
@Override
public void onImageChosen(final ChosenImage chosenImage) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (chosenImage != null) {
isPicChange = "1";
mFileTemp = new File(chosenImage.getFileThumbnailSmall());
if (imageStatus.equals("user")) {
Picasso.with(ActivityDriverProfile.this).load(mFileTemp).transform(new CircleTransform()).resize(300, 300).centerCrop()
.skipMemoryCache().into(reviewUserImage);
}
if (imageStatus.equals("nicfront")) {
Picasso.with(ActivityDriverProfile.this).load(mFileTemp).resize(470, 300).centerCrop()
.skipMemoryCache().into(nicfront);
}
if (imageStatus.equals("nicback")) {
Picasso.with(ActivityDriverProfile.this).load(mFileTemp).resize(470, 300).centerCrop()
.skipMemoryCache().into(nicback);
}
}
}
});
}
@Override
public void onError(String s) {
}
private void chooseImageFromGallery() {
// int chooserType = ChooserType.REQUEST_PICK_PICTURE;
imageChooserManager = new ImageChooserManager(this, ChooserType.REQUEST_PICK_PICTURE, "myfolder", true);
imageChooserManager.setImageChooserListener(ActivityDriverProfile.this);
try {
imageChooserManager.choose();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && (requestCode == ChooserType.REQUEST_PICK_PICTURE || requestCode == ChooserType.REQUEST_CAPTURE_PICTURE)) {
imageChooserManager.submit(requestCode, data);
}
}
答案 0 :(得分:0)
我只使用它并解决我的问题
mFileTemp = new File(chosenImage.getFilePathOriginal());
deleteImage(new File(chosenImage.getFileThumbnail()));
deleteImage(new File(chosenImage.getFileThumbnailSmall()));