当前位置: 首页>編程日記>正文

android截屏加水印,Android截图以及加水印Demo

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、效果演示

0818b9ca8b590ca3270a3433284dd417.png


https://www.fengoutiyan.com/post/13666.html

相关文章:

  • Android去水印
  • 水印截图模拟器
  • 截图怎么带水印
  • b站截图怎么去水印
  • 安卓截屏软件
  • 微截图2去水印版
  • 微商水印做聊天截图
  • b站截图不显示水印
  • 鏡像模式如何設置在哪,圖片鏡像操作
  • 什么軟件可以把圖片鏡像翻轉,C#圖片處理 解決左右鏡像相反(旋轉圖片)
  • 手機照片鏡像翻轉,C#圖像鏡像
  • 視頻鏡像翻轉軟件,python圖片鏡像翻轉_python中鏡像實現方法
  • 什么軟件可以把圖片鏡像翻轉,利用PS實現圖片的鏡像處理
  • 照片鏡像翻轉app,java實現圖片鏡像翻轉
  • 什么軟件可以把圖片鏡像翻轉,python圖片鏡像翻轉_python圖像處理之鏡像實現方法
  • matlab下載,matlab如何鏡像處理圖片,matlab實現圖像鏡像
  • 圖片鏡像翻轉,MATLAB:鏡像圖片
  • 鏡像翻轉圖片的軟件,圖像處理:實現圖片鏡像(基于python)
  • canvas可畫,JavaScript - canvas - 鏡像圖片
  • 圖片鏡像翻轉,UGUI優化:使用鏡像圖片
  • Codeforces,CodeForces 1253C
  • MySQL下載安裝,Mysql ERROR: 1253 解決方法
  • 勝利大逃亡英雄逃亡方案,HDU - 1253 勝利大逃亡 BFS
  • 大一c語言期末考試試題及答案匯總,電大計算機C語言1253,1253《C語言程序設計》電大期末精彩試題及其問題詳解
  • lu求解線性方程組,P1253 [yLOI2018] 扶蘇的問題 (線段樹)
  • c語言程序設計基礎題庫,1253號C語言程序設計試題,2016年1月試卷號1253C語言程序設計A.pdf
  • 信奧賽一本通官網,【信奧賽一本通】1253:抓住那頭牛(詳細代碼)
  • c語言程序設計1253,1253c語言程序設計a(2010年1月)
  • 勝利大逃亡英雄逃亡方案,BFS——1253 勝利大逃亡
  • 直流電壓測量模塊,IM1253B交直流電能計量模塊(艾銳達光電)
  • c語言程序設計第三版課后答案,【渝粵題庫】國家開放大學2021春1253C語言程序設計答案
  • 18轉換為二進制,1253. 將數字轉換為16進制
  • light-emitting diode,LightOJ-1253 Misere Nim
  • masterroyale魔改版,1253 Dungeon Master
  • codeformer官網中文版,codeforces.1253 B
  • c語言程序設計考研真題及答案,2020C語言程序設計1253,1253計算機科學與技術專業C語言程序設計A科目2020年09月國家開 放大學(中央廣播電視大學)
  • c語言程序設計基礎題庫,1253本科2016c語言程序設計試題,1253電大《C語言程序設計A》試題和答案200901
  • 肇事逃逸車輛無法聯系到車主怎么辦,1253尋找肇事司機