From 4af5204af0c3407624bcc36aefc0dab66684e48e Mon Sep 17 00:00:00 2001 From: wty <2479585756@qq.com> Date: Tue, 25 Oct 2022 10:59:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E5=9B=BE=E7=89=87=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=B8=A6=E6=9C=89=E6=97=B6=E9=97=B4=E7=9A=84=E6=B0=B4=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../easyphotos/demo/SampleActivity.java | 39 +++++++++++++++++++ .../main/res/menu/activity_sample_drawer.xml | 4 ++ demo/src/main/res/values/strings.xml | 1 + 3 files changed, 44 insertions(+) diff --git a/demo/src/main/java/com/huantansheng/easyphotos/demo/SampleActivity.java b/demo/src/main/java/com/huantansheng/easyphotos/demo/SampleActivity.java index d76346b0..01ca85f0 100644 --- a/demo/src/main/java/com/huantansheng/easyphotos/demo/SampleActivity.java +++ b/demo/src/main/java/com/huantansheng/easyphotos/demo/SampleActivity.java @@ -408,6 +408,45 @@ public void onCancel() { break; + case R.id.addWatermarkWithText: //给图片添加带有时间的水印 + + EasyPhotos.createAlbum(this, false, true, GlideEngine.getInstance()) + .setFileProviderAuthority("com.huantansheng.easyphotos.demo.fileprovider") + .setPuzzleMenu(false) + .start(new SelectCallback() { + @Override + public void onResult(ArrayList photos, boolean isOriginal) { + selectedPhotoList.clear(); + adapter.notifyDataSetChanged(); + + //这一步如果图大的话会耗时,但耗时不长,建议在异步操作。另外copy出来的bitmap在确定不用的时候记得回收,如果你用Glide操作过copy + // 出来的bitmap那就不要回收了,否则Glide会报错。 + Bitmap watermark = BitmapFactory.decodeResource(getResources(), + R.drawable.watermark).copy(Bitmap.Config.RGB_565, true); + try { + bitmap = + BitmapFactory.decodeStream(getContentResolver().openInputStream(photos.get(0).uri)).copy(Bitmap.Config.ARGB_8888, true); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + //给图片添加水印的api + Date curDate = new Date(System.currentTimeMillis());//获取当前时间 + SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); + String str = formatter.format(curDate); + bitmap = EasyPhotos.addWatermarkWithText(watermark, bitmap, 1080, str, 20, 20, true, photos.get(0).orientation); + + bitmapView.setVisibility(View.VISIBLE); + bitmapView.setImageBitmap(bitmap); + Toast.makeText(SampleActivity.this, "水印在左下角", Toast.LENGTH_SHORT).show(); + + } + + @Override + public void onCancel() { + + } + }); + case R.id.puzzle: EasyPhotos.createAlbum(this, false, false, GlideEngine.getInstance()) .setCount(9) diff --git a/demo/src/main/res/menu/activity_sample_drawer.xml b/demo/src/main/res/menu/activity_sample_drawer.xml index 8b276805..4c8d56cf 100644 --- a/demo/src/main/res/menu/activity_sample_drawer.xml +++ b/demo/src/main/res/menu/activity_sample_drawer.xml @@ -91,6 +91,10 @@ android:id="@+id/addWatermark" android:title="@string/addWatermark" /> + + diff --git a/demo/src/main/res/values/strings.xml b/demo/src/main/res/values/strings.xml index 632427b4..e238d008 100644 --- a/demo/src/main/res/values/strings.xml +++ b/demo/src/main/res/values/strings.xml @@ -21,6 +21,7 @@ 相册 (复杂选择情况,动态单一类型) 相机(有宽高) 图片添加水印 + 图片添加带文字和图片的水印 人脸检测 拼图(作为单独功能使用)