如何在拍摄图像上添加时间戳?

时间:2019-01-19 17:24:32

标签: android

我正在尝试开发相机应用。我需要在其中捕获图像,然后在保存之前,需要在捕获的图像上添加一些文本。可以在Android的运行时编辑捕获的图像吗?

demo output

activity_camera.xml

<ImageView
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:id="@+id/imageView"
    android:layout_weight="9"
    />
<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/btnCamera"
    android:layout_weight="1"
    android:background="@android:color/holo_blue_dark"
    android:textColor="@android:color/white"
    android:text="Open Camera"
    />

CameraActivity.java

public class CameraActivity extends Activity {
    private ImageView imageView;
    private Camera camera;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);
        Button btnCamera = (Button)findViewById(R.id.btnCamera);
        imageView = (ImageView)findViewById(R.id.imageView);
        btnCamera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(CameraActivity.this, "Camera Text", Toast.LENGTH_SHORT).show();
                File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "Test.jpg");
                Uri iImageOutputUri = Uri.fromFile(file);
                AppPermission appPermission = new AppPermission(CameraActivity.this);
                if (!appPermission.checkPermissionForCamera()) {
                appPermission.requestPermissionForCamera();
                }else {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(intent,0);
                }
            }
        });
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Toast.makeText(CameraActivity.this, "Camera Text 2", Toast.LENGTH_SHORT).show();
        // Process result for camera activity.
        // If camera take picture success.
        if (resultCode == RESULT_OK) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String currentDateandTime = sdf.format(new Date());
            Toast.makeText(this, currentDateandTime, Toast.LENGTH_SHORT).show();
            Bitmap bitmap = (Bitmap) data.getExtras().get("data");
            imageView.setImageBitmap(bitmap);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

如果要在单击的图像上显示时间戳,可以按照以下步骤操作:

  1. 点击图像后,它就会出现在图像视图中。

  2. 在该图像视图上,已经有一个带时间戳的textview设置textview,并以编程方式获取同时包含图像视图和textview的相对布局的屏幕截图。

如果您在任何地方都需要帮助,请告诉我。