我已经花了4个小时尝试解决这个问题。我有来自Imgaeview的图像,我想使用不同的名称将其保存到图库中,但名称仍然相同。
SimpleWay上的方法
public String StoringImage(Bitmap bitmap, String nameImage) {
String savedImageURL = MediaStore.Images.Media.insertImage(
getContentResolver(),
bitmap,
nameImage + ".jpg",
null
);
return savedImageURL;
}
public void OpenAlertDialog(Context context, final Bitmap bitmap, final
TextView textView, String title){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
final EditText editText = new EditText(context);
builder.setTitle(title)
.setView(editText);
builder.setPositiveButton("Ok", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String name = editText.getText().toString();
String textImge = StoringImage(bitmap, name);
textView.setText(textImge);
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
我用于CameraActivity的侦听器
@Override
public void initListener() {
bCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pickImage(CameraActivity.this, PICK_CAMERA);
imageView.setDrawingCacheEnabled(true);
}
});
bChooseFile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pickImage(CameraActivity.this, PICK_GALLERY);
}
});
bCitra.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
bSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap bitmap = takeBitmap(imageView);
OpenAlertDialog(CameraActivity.this, bitmap, textView, "Input");
}
});
bGray.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap grayBitmap = openCVConverter.ConverToGray(takeBitmap(imageView));
setBitmap(grayBitmap);
}
});
bBinary.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap binaryBitmap = openCVConverter.RGBImageToBinary(takeBitmap(imageView));
setBitmap(binaryBitmap);
}
});
}
这是我已经保存的图像,但名称仍然相同。