android 暗水印_第1张图片android 暗水印_第2张图片

 

GITHUB:https://github.com/hyyz3293/DarkWatermark  -------------------------

 

第一步:android studio 配置 opcv环境 https://opencv.org/opencv-3-4-1/

OPCV 环境配置:a:下载安卓opcv:  https://opencv.org/opencv-3-4-1/  (我用的是openCVLibrary341) b:将下载好后的(sdk\java)    导入 android studio 项目中: File ->  New -> Import Module  c:删除module中的      更改项目项目配置 与你的一样d:将module中libs里面的架包 (OpenCV-android-sdk\sdk\native\libs) 拷贝入自己的项目中  e:自己项目加入配置 让app包,与新添加的这个OpenCV库关联   implementation project(':openCVLibrary341')     sourceSets {     main {        //说明so的路径为该libs路径,关联所有地图SDK的so文件        jniLibs.srcDir 'libs'    }  }   f: 加入 //以下很重要  //将添加的.so文件,打包成jar  task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {      destinationDir file("$buildDir/native-libs")      baseName 'native-libs'      from fileTree(dir: 'libs', include: '**/*.so')      into 'lib/'  }  tasks.withType(JavaCompile) {      compileTask -> compileTask.dependsOn(nativeLibsToJar)  }

第二步:判断Opcv是否集成成功 //初始化 if (OpenCVLoader.initDebug())

    可根据灰色测试按钮测试        Mat src = new Mat();//Mat是OpenCV的一种图像格式    Mat temp = new Mat();    Mat dst = new Mat();    Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.mipmap.a);    Utils.bitmapToMat(bitmap, src);    Imgproc.cvtColor(src, temp, Imgproc.COLOR_RGB2BGR);    Imgproc.cvtColor(temp, dst, Imgproc.COLOR_BGR2GRAY);    Utils.matToBitmap(dst, bitmap);    img.setImageBitmap(bitmap);    src.release();    temp.release();    dst.release();

第三步: 开始写代码了

    1、添加水印 并保存图片到本地哟    Bitmap bt = ImgUtils.drawableToBitmap(getResources().getDrawable(R.mipmap.a));    Mat src = new Mat(bt.getHeight(), bt.getWidth(), CvType.CV_8U);    Utils.bitmapToMat(bt, src);    Mat imageMat = OpcvImgUtils.addImageWatermarkWithText(src, "Jack666");    Bitmap bt3 = null;    bt3 = Bitmap.createBitmap(imageMat.cols(), imageMat.rows(), Bitmap.Config.RGB_565);    Utils.matToBitmap(imageMat, bt3);   File root = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), "WaterMark");   if ((root.exists() || root.mkdir()) && root.isDirectory()) {        filePath = root.getAbsolutePath();    }   path = filePath + "/" + ImgUtils.getTimeStampFileName(0);   ImageUtils.save(bt3, path,  Bitmap.CompressFormat.PNG);   LogUtils.e(path);   Glide.with(this).load(path).into(imgTest);            2、从本地图片中 提取水印哟            Bitmap bitmap = BitmapFactory.decodeFile(path);        Mat temp = new Mat();        Utils.bitmapToMat(bitmap, temp);        Mat showMat = OpcvImgUtils.getImageWatermarkWithText(temp);        Bitmap  bt4 = Bitmap.createBitmap(showMat.cols(), showMat.rows(), Bitmap.Config.RGB_565);        Utils.matToBitmap(showMat, bt4);        imgTest2.setImageBitmap(bt4);        String paths = filePath + "/" + ImgUtils.getTimeStampFileName(0);        ImageUtils.save(bt4, paths ,  Bitmap.CompressFormat.PNG);          Bitmap bitmap = BitmapFactory.decodeFile(path);        Mat temp = new Mat();        Utils.bitmapToMat(bitmap, temp);        Mat showMat = OpcvImgUtils.getImageWatermarkWithText(temp);        Bitmap  bt4 = Bitmap.createBitmap(showMat.cols(), showMat.rows(), Bitmap.Config.RGB_565);        Utils.matToBitmap(showMat, bt4);        imgTest2.setImageBitmap(bt4);        String paths = filePath + "/" + ImgUtils.getTimeStampFileName(0);        ImageUtils.save(bt4, paths ,  Bitmap.CompressFormat.PNG);

更多相关文章

  1. Android中上传图片到服务端C#接收图
  2. Android 实践项目开发 总结
  3. Android获取手机本地图片缩略图
  4. 开源项目之Android RibbonMenu(导航菜单)
  5. android imageswitcher gallery 根据数据库内图片名字进行查看/
  6. Android 项目开发基础再回顾(一)
  7. Android OkHttp3 上传多张图片
  8. Android中TextView中加图片,超链接,一部分字或者背景变色。不断补
  9. GitHub 优秀的 Android 开源项目 淘宝技术牛p博客整理开发中最常

随机推荐

  1. Android定义定时器实现定时任务(亲测可用
  2. ViewPage固定每页加载的数量。进行翻页
  3. android 自定义view实现图形移动
  4. (ios实战)实现类似于android 的toast控件
  5. android输入法问题
  6. 你需要了解下Android(安卓)View的更新req
  7. android 播放器合集打包(源码来源网络)
  8. Android的Linux内核的电源管理:概述
  9. [置顶] Android(安卓)WebView 踩过的坑
  10. android radioButton 改变圆圈大小