Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

给图片添加带有时间的水印 #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Photo> 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)
Expand Down
4 changes: 4 additions & 0 deletions demo/src/main/res/menu/activity_sample_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
android:id="@+id/addWatermark"
android:title="@string/addWatermark" />

<item
android:id="@+id/addWatermarkWithText"
android:title="@string/addWatermarkWithText" />

<item
android:id="@+id/puzzle"
android:title="@string/puzzle" />
Expand Down
1 change: 1 addition & 0 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="album_complex_selector2">相册 (复杂选择情况,动态单一类型)</string>
<string name="camera">相机(有宽高)</string>
<string name="addWatermark">图片添加水印</string>
<string name="addWatermarkWithText">图片添加带文字和图片的水印</string>
<string name="face_detection">人脸检测</string>
<string name="puzzle">拼图(作为单独功能使用)</string>

Expand Down