【问题标题】:How to add timestamp over an capture image?如何在捕获图像上添加时间戳?
【发布时间】:2019-01-19 17:24:32
【问题描述】:

我正在尝试开发相机应用程序。在其中我需要捕获图像,然后在保存之前我需要在捕获的图像上添加一些文本。是否可以在运行时在 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);
        }
    }
}

【问题讨论】:

    标签: android


    【解决方案1】:

    如果您想在点击的图片上显示时间戳,您可以按照以下步骤操作:

    1. 点击图片后进入图片视图。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 2012-07-11
      • 2020-10-04
      • 1970-01-01
      • 2017-10-19
      • 2022-08-20
      • 1970-01-01
      相关资源
      最近更新 更多