Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 照片上的文字(日期)印章_Android_Date_Camera_Photo - Fatal编程技术网

Android 照片上的文字(日期)印章

Android 照片上的文字(日期)印章,android,date,camera,photo,Android,Date,Camera,Photo,是否可以合并从相机拍摄的文字和照片? 我想在照片上标注日期和时间,但我在谷歌上找不到任何东西。 使用方法decodeByteArray 使用上面创建的位图创建画布对象 在画布对象上使用drawText方法将文本写入照片 使用下面的代码实现您所需的功能 Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.cuty); // the original file is cuty.jpg i added

是否可以合并从相机拍摄的文字和照片? 我想在照片上标注日期和时间,但我在谷歌上找不到任何东西。

  • 使用方法
    decodeByteArray
  • 使用上面创建的位图创建画布对象
  • 在画布对象上使用
    drawText
    方法将文本写入照片
使用下面的代码实现您所需的功能

        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();
        }
您必须在清单文件中使用以下权限

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

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


对于我的设备,访问外部SD卡的路径为/sdcard,对于其他设备,路径可能有所不同。某些设备可能有/mnt/sdcard,可能是用于内部sd卡。在使用此代码段之前,请检查它。

你好,Yugandhar Babu.希望你做得很好…我想在视频录制上添加日期和时间戳,当我像上面的图像代码一样播放视频显示日期和时间时..我已经完成了您的图像代码及其工作,现在我还想为视频添加此功能..任何帮助都将不胜感激..谢谢..@saurabhtrivedi抱歉,我无法帮助您的要求。现在我忙于安卓移植,而不是安卓应用程序开发。@YugandharBabu,你有视频解决方案吗?当我加载从相机拍摄的大图像时,我出现内存不足异常,我还尝试了安卓:largeHeap=“true”仍然没有设置底部时间戳的方法??