使用“requestCode == REQUEST_IMAGE_CAPTURE”的android相机意图如何工作?如果我拍第二张照片,缩略图会刷新到新照片,还是会保持不变? (即uri将被重写)
我遇到的问题是,我在ImageSlider中有一张照片,我在照片捕捉时添加了一张图片(它可以正常工作),但是当我关闭所有照片并拍摄另一张照片时,会显示相同的图像原来的。我检查了所有的输出流,看起来我已经刷了它们,我甚至尝试删除在FileStream中创建的临时文件,但它不起作用。见下面的代码:
相机捕捉类:
// Captures the picture
public void captureCameraPhoto() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, ACTION_CAPTURE);
}
关于活动结果(检索缩略图并显示)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
final String name = "Take Photo";
if (requestCode == ACTION_CAPTURE && resultCode == Activity.RESULT_OK) {
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] byteArray = bos.toByteArray();
try {
bos.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
OutputStream os = getActivity().openFileOutput("cardImage", Context.MODE_PRIVATE);
os.write(byteArray);
os.flush();
os.close();
File file = getActivity().getFileStreamPath("cardImage");
Log.e("MADEFILE", file.toString());
cardMap.put(name, file);
// ADD SLIDER
TextSliderView textSliderView = new TextSliderView(getActivity());
textSliderView
.description("Custom Photo")
.image(cardMap.get(name))
.setScaleType(BaseSliderView.ScaleType.CenterInside)
.setOnSliderClickListener(new BaseSliderView.OnSliderClickListener() {
@Override
public void onSliderClick(BaseSliderView slider) {
Toast.makeText(getActivity(), String.valueOf(sliderShow.getCurrentPosition()), Toast.LENGTH_SHORT).show();
}
});
try {
sliderShow.removeSliderAt(6);
} catch (Exception ignored) {
}
sliderShow.addSlider(textSliderView);
sliderShow.movePrevPosition();
sliderShow.movePrevPosition();
currentOrder.add("cardImage");
picturetaken = true;
bitmap.recycle();
} catch (IOException e) {
e.printStackTrace();
}
}
}
退出此对话片段时:
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Boolean deleteFile = getActivity().deleteFile("cardImage");
Toast.makeText(getActivity(), String.valueOf(deleteFile), Toast.LENGTH_LONG).show();
dismiss();
}
});