照片上的文字(日期)印章 [英] Text (date) stamp on photo

查看:51
本文介绍了照片上的文字(日期)印章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以合并从相机拍摄的文字和照片?我想在照片上标记日期和时间,但在Google上找不到任何内容.

Is it possible merge text and photo taken from camera? I would like to stamp date and time on photo but I don't find anything on Google.

推荐答案

使用以下代码实现所需的功能.

Use below code to achieve what you required.

        Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.cuty); // the original file is cuty.jpg i added in resources
        Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateTime = sdf.format(Calendar.getInstance().getTime()); // reading local time in the system

        Canvas cs = new Canvas(dest);
        Paint tPaint = new Paint();
        tPaint.setTextSize(35);
        tPaint.setColor(Color.BLUE);
        tPaint.setStyle(Style.FILL);
        cs.drawBitmap(src, 0f, 0f, null);
        float height = tPaint.measureText("yY");
        cs.drawText(dateTime, 20f, height+15f, tPaint);
        try {
            dest.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/sdcard/timeStampedImage.jpg")));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

您必须在清单文件中使用以下权限.

You have to use below permission in manifest file.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

如有任何疑问,请随时提出.我要在图像的左上角添加时间戳,您可以将其更改为图像上的任何位置.

If you have any doubts feel free to ask. I am adding time stamp at top left corner of image, you can change it to anywhere on the image.

对于我的设备,访问外部SD卡的路径为/sdcard ,对于其他设备,该路径可能会有所不同.某些设备可能具有/mnt/sdcard ,可能是用于内部SD卡的.在使用此代码段之前,只需检查一下即可.

For my device the path is /sdcard to access external SD card, it may vary for other devices. Some devices may have /mnt/sdcard may be it is for internal sd cards. Just check it while before using this code snippet.

这篇关于照片上的文字(日期)印章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆