gpt4 book ai didi

android - 照片上的文字(日期)戳

转载 作者:太空宇宙 更新时间:2023-11-03 12:00:44 26 4
gpt4 key购买 nike

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

最佳答案

使用下面的代码来实现你所需要的。

        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();
}

您必须在 list 文件中使用以下权限。

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

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

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

关于android - 照片上的文字(日期)戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9045826/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com