android截屏加水印,Android截图以及加水印Demo
实现一个简单的截图功能以及给图片添加水印的功能,直接上代码!
一、代码实现
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.text.format.Time;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class GetAppThumbnailActivity extends Activity {
private Button btnThum;
private ImageView imgThum;
private ImageView imgSource;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setupViews();
}
private void setupViews() {
btnThum = (Button) findViewById(R.id.getThum);
imgThum = (ImageView) findViewById(R.id.setThum);
imgSource = (ImageView) findViewById(R.id.source);
btnThum.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Bitmap bitmap = getViewBitmap(imgSource);
Bitmap bitmap1 = createBitmap(bitmap, "haha哈哈");
if (bitmap1 != null) {
imgThum.setImageBitmap(bitmap1);
}
}
});
}
/**
* Draw the view into a bitmap.
*/
private Bitmap getViewBitmap(View v) {
v.clearFocus();
v.setPressed(false);
boolean willNotCache = v.willNotCacheDrawing();
v.setWillNotCacheDrawing(false);
// Reset the drawing cache background color to fully transparent
// for the duration of this operation
int color = v.getDrawingCacheBackgroundColor();
v.setDrawingCacheBackgroundColor(0);
if (color != 0) {
v.destroyDrawingCache();
}
v.buildDrawingCache();
Bitmap cacheBitmap = v.getDrawingCache();
if (cacheBitmap == null) {
return null;
}
Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
// Restore the view
v.destroyDrawingCache();
v.setWillNotCacheDrawing(willNotCache);
v.setDrawingCacheBackgroundColor(color);
return bitmap;
}
// 给图片添加水印
private Bitmap createBitmap(Bitmap src, String str) {
Time t = new Time();
t.setToNow();
int w = src.getWidth();
int h = src.getHeight();
String mstrTitle = "截图时间:"+t.hour + ":" + t.minute + ":" + t.second;
Bitmap bmpTemp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas canvas = new Canvas(bmpTemp);
Paint p = new Paint();
String familyName = "宋体";
Typeface font = Typeface.create(familyName, Typeface.BOLD);
p.setColor(Color.BLUE);
p.setTypeface(font);
p.setTextSize(22);
canvas.drawBitmap(src, 0, 0, p);
canvas.drawText(mstrTitle, 0, 20, p);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
return bmpTemp;
}
}
2、资源描述文件
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:id="@+id/getThum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/str_getthum"/>
android:id="@+id/setThum"
android:background="@drawable/no_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:id="@+id/source"
android:background="@drawable/v"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
4、效果演示
android截屏加水印,Android截图以及加水印Demo相关推荐
- Android 截屏监听(截图分享功能实现)
具体来说就是,检测到了用户在应用内有截图,弹出一个分享界面, 在截图下方添加一个二维码,进行分享. ●●● 前言 Android系统没有直接对截屏事件监听的接口,也没有广播,只能自己动手来丰衣足食, ...
- android 截屏 简书,Android 内置应用截屏方法
Android 中,内置应用如何更好的截屏 在开发系统应用的时候,有时候需要用到截屏,因为 View.getDrawingCache() 截不到状态栏,所以这个方案不理想 这有一个更好的方案,就是用 ...
- xamarin Android 截屏,xamarin开发android收集的一些工具
xamarin开发android收集的一些工具 工欲善其事,必先利其器,从16年下半年开始做xamarin相关的开发,平时使用的一些工具和google插件给大家分享一下,都有下载地址,持续更新. Vi ...
- android 截屏指定区域,Android截图 截取ContentView 截取指定的View并且保存
释放双眼,带上耳机,听听看~! 截取DecorView getWindow().getDecorView().setDrawingCacheEnabled(true); try { File myCa ...
- Android截屏截图的几种方法总结
Android截屏 Android截屏的原理:获取具体需要截屏的区域的Bitmap,然后绘制在画布上,保存为图片后进行分享或者其它用途 一.Activity截屏 1.截Activity界面(包含空白的 ...
- Android截屏截图方法汇总(Activity、View、ScrollView、ListView、RecycleView、WebView截屏截图)
Android截屏 Android截屏的原理:获取具体需要截屏的区域的Bitmap,然后绘制在画布上,保存为图片后进行分享或者其它用途 一.Activity截屏 1.截Activity界面(包含空白的 ...
- android 6 截屏快捷键是什么,一加6怎么截图 一加6截屏方法汇总
今天是一加6的首销日,通过今天的表现来看一加6异常火爆,非常受欢迎.相信要不了几天大家会陆陆续续收到真机,对于使用过程当中难免会使用到截屏.那么全新一代的一加6怎么截图呢?下面"脚本之家&q ...
- android 9平板电脑截屏,一加9怎么截图 一加9截屏方法
截屏是我们使用手机的时候必须用到的一点,不管是保留什么还是分享喜悦都需要用到这个功能.最近爆火的一加9它的截屏方式是怎样的呢?接下来我们一起来了解一下吧. 1.一加9的截屏方式 普通截屏方法: 同时按 ...
- android盒子截图,Android截屏截图的几种方法总结
Android截屏 Android截屏的原理:获取具体需要截屏的区域的Bitmap,然后绘制在画布上,保存为图片后进行分享或者其它用途 一.Activity截屏 1.截Activity界面(包含空白的 ...
- zte android截屏快捷键,中兴红牛V5手机怎么截屏 中兴红牛V5截图技巧图解
中兴红牛V5手机截屏怎么截的呢,对于刚开始用智能机的我来说,是一个不小的尝试,包括我刚知道的候一样,下面由本小编教大家怎么使用中兴红牛手机截屏和截图的技巧.操作步骤如下: 红牛V5怎么截屏 中兴红牛V ...
最新文章
- JavaScript中闭包实现的私有属性的getter()和setter()方法
- 7个CSS你可能不知道的技巧
- 【BZOJ3218】a+b problem (最小割 + 主席树)
- P4336 [SHOI2016]黑暗前的幻想乡
- 【java机器学习】决策树算法
- java远程插件动态注册机制_Spring运行时动态注册bean的方法
- 诗与远方:无题(三十一)- 祝我单身
- python下载大文件mp4_Python3 使用requests模块显示下载大文件显示进度
- Web前端初级问题—ajax登录跳转登录实现
- PHP拼接唯一索引,合并两个数组数据
- 国家多部委发布13份“十四五”规划,115项重大工程​
- excel表格数据合并的简便操作
- 微信小程序-调查问卷
- 传音控股上海特性和功耗开发团队招期招聘优秀工程师啦
- 浙大远程教育计算机小抄,一张A4纸能写多少个字?看完浙大考生的“小抄”,网友:稳过!...
- 大厂对学历的要求是什么?如果学历不够,有这些补救的办法!
- c++数据结构350、121
- Word合并所有段落再按字数划分段落
- xcode 工程常见问题
- 通俗易通解释SLAM问题的数学描述:运动方程和观测方程
热门文章
- 读书笔记 - 多Agent强化学习下的自适应交通信号控制研究综述2017
- 二维码的纠错码原理及如何纠错(1)
- 用GridView做国际象棋
- 通过串口波特率计算数据传输速率(每秒字节数)
- 基于STM32居家加湿器控制仿真设计-基于STM32热释人体感应智能门禁报警设计-基于STM32无刷电机BLDC速度控制器设计-基于STM32智能路灯灯光自动控制设计-基于单片机PID控制算法开关电源
- iec611313标准下载_IEC611313标准及其实现
- 非常有意义的数学公式
- 为解放程序员而生,网易重磅推“场景化云服务”,强势进军云计算市场
- Vmware安装Vmware Tools工具
- 2015年OA选型一览表