我在绘制Android应用程序时使用File(MediaStore.Images.Media.insertImage)保存绘图时遇到问题。
当我保存图形时,在图形属性中,它显示两个不同的名称:
要清楚,这是一个捕获:
为什么我会这样?
代码:
else if (view.getId() == R.id.btn_guardar) {
// save drawing
AlertDialog.Builder saveDialog = new AlertDialog.Builder(this);
saveDialog.setTitle("Guardar imagen");
saveDialog.setMessage("¿Guardar imagen en la galería?");
saveDialog.setPositiveButton("Si",
new DialogInterface.OnClickListener() {
@SuppressWarnings("null")
public void onClick(DialogInterface dialog, int which) {
// save drawing
drawView.setDrawingCacheEnabled(true);
// attempt to save
File imgGuardada = new File(MediaStore.Images.Media
.insertImage(getContentResolver(), drawView
.getDrawingCache(), "dibujo",
"save image"));
// feedback
if (imgGuardada !=null) {
Toast savedToast = Toast
.makeText(
getApplicationContext(),
"La imagen ha sido guardada en el fondo del mar. Es broma, está en la galería.",
Toast.LENGTH_SHORT);
savedToast.show();
} else {
Toast unsavedToast = Toast
.makeText(
getApplicationContext(),
"La imagen no se ha guardado. Ha sido enviada a Mordor",
Toast.LENGTH_SHORT);
unsavedToast.show();
}
drawView.destroyDrawingCache();
}
});
saveDialog.setNegativeButton("Nope",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
saveDialog.show();
}
感谢您的帮助!
注意:我有Android 4.4。是因为那个吗?