Android實(shí)現(xiàn)為圖片添加水印
更新時間:2020年04月18日 10:32:29 作者:葉應(yīng)是葉
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)為圖片添加水印的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了Android實(shí)現(xiàn)為圖片添加水印的具體代碼,供大家參考,具體內(nèi)容如下
添加水印的方法挺簡單的,具體內(nèi)容如下
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView iv = (ImageView) findViewById(R.id.imageView); Drawable drawable = ContextCompat.getDrawable(this, R.drawable.image); BitmapDrawable bd = (BitmapDrawable) drawable; Bitmap bmp = bd.getBitmap(); Bitmap bitmap = createWatermark(bmp, "葉應(yīng)是葉" + "http://blog.csdn.net/new_one_object"); iv.setImageBitmap(bitmap); } private Bitmap createWatermark(Bitmap bitmap, String mark) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint p = new Paint(); // 水印顏色 p.setColor(Color.parseColor("#c5576370")); // 水印字體大小 p.setTextSize(150); //抗鋸齒 p.setAntiAlias(true); //繪制圖像 canvas.drawBitmap(bitmap, 0, 0, p); //繪制文字 canvas.drawText(mark, 0, h / 2, p); canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore(); return bmp; } }
效果圖
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android實(shí)現(xiàn)環(huán)信修改頭像和昵稱
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)環(huán)信修改頭像和昵稱,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02Android 中RecyclerView頂部刷新實(shí)現(xiàn)詳解
這篇文章主要介紹了Android 中RecyclerView頂部刷新實(shí)現(xiàn)詳解的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下2017-10-10Flutter時間軸Timeline的實(shí)現(xiàn)
時間軸在很多地方都可以用的到,本文介紹了Flutter時間軸Timeline的實(shí)現(xiàn),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-05-05詳解Matisse與Glide--java.lang.NoSuchMethodError:com.bumptech.gl
這篇文章主要介紹了在使用Matisse與glide4.0.0以及4.0.0之后的版本過程中,碰到該問題java.lang.NoSuchMethodError:com.bumptech.glide.RequestManager.load的解決方法2021-08-08