Android 图片加水印
首先可以肯定 java.awt 在android中是不可用的
直接上代码:
/** * * @param src 原图片 * @param watermark 要打的水印图片 * @param title 要打的水印文字 * @param densityDpi 屏幕位深密度 * @return Bitmap 打好水印的图片 */ public static Bitmap createBitmap(String file, Bitmap watermark, String title,int densityDpi) { int dpi = densityDpi; LogPrint.Print("watermark===createBitmap====dpi"+dpi); // 读取原图片信息 File srcImgFile = new File(file); Bitmap roratesrc = BitmapFactory.decodeFile(file); Bitmap src = rorateBitamp(90, roratesrc); if (src == null) { return null; } int srcWidth = src.getWidth(); int srcHeight = src.getHeight(); Paint paint = new Paint(); // ARGB_8888 Bitmap newb = Bitmap .createBitmap(srcWidth, srcHeight, Config.ARGB_8888);// 创建一个新的和src长度宽度一样的位图 // 把创建的位图作为画板 Canvas cv = new Canvas(newb); // 在0,0坐标开始画入src cv.drawBitmap(src, 0, 0, paint); if (watermark != null) { int ww = watermark.getWidth(); int wh = watermark.getHeight(); paint.setAlpha(50); // cv.drawBitmap(watermark, srcWidth - ww + 1, srcHeight - wh +1,paint);// 在src的右下角画入水印 cv.drawBitmap(watermark, 1, 1, paint);// 在src的左上角画入水印 } // 加入文字 if (title != null) { String familyName = "宋体"; Typeface font = Typeface.create(familyName, Typeface.NORMAL); TextPaint textPaint = new TextPaint(); textPaint.setColor(Color.WHITE); textPaint.setTypeface(font); if(dpi <= 120){//qvga 240X400 textPaint.setTextSize(5); }else if(dpi <= 160){//hvga 320X480 textPaint.setTextSize(8); }else if(dpi <= 240){//wvga 480X800 textPaint.setTextSize(10); if (Configs.WIDTH > 700) { textPaint.setTextSize(15); } }else if(dpi <= 320){// 1280*720 textPaint.setTextSize(15); if (Configs.WIDTH > 2000 ) { textPaint.setTextSize(72); } }else { //更大屏幕分辨率 textPaint.setTextSize(72); } // 这里是自动换行的 StaticLayout layout = new StaticLayout(title, textPaint, srcWidth, Alignment.ALIGN_NORMAL, 1.0F, 0.0F, true); layout.draw(cv); // 文字加在左上角 //cv.drawText(title,40,40,paint); } else { paint.setColor(Color.WHITE); paint.setTextSize(20); cv.drawText("测试", 1, 1, paint); } cv.save(Canvas.ALL_SAVE_FLAG);// 保存 cv.restore();// 存储 ByteArrayOutputStream baos = new ByteArrayOutputStream(); newb.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] bytes = baos.toByteArray(); try { FileOutputStream fileOutputStream = new FileOutputStream(srcImgFile); fileOutputStream.write(bytes); fileOutputStream.flush(); fileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } return newb; }
示例:
//图片添加文字水 if (mlocation != null) { BitmapUtils.createBitmap(mPictureFile.getAbsolutePath(), null,"经纬度:"+mlocation.getLongitude()+","+mlocation.getLatitude()+"\t\t角度:"+mlocation.getBearing()+"度\t\t"+"方向:"+sensorOrientation+"度\t\t速度:"+mlocation.getSpeed()+"公里/小时\n拍摄时间:"+imageFormat.format(System.currentTimeMillis()),getResources().getDisplayMetrics().densityDpi); }else { BitmapUtils.createBitmap(mPictureFile.getAbsolutePath(), null,"经纬度:"+0+","+0+"\t\t角度:"+0+"度\t\t"+"方向:"+sensorOrientation+"度\t\t速度:"+0+"公里/小时\n拍摄时间:"+imageFormat.format(System.currentTimeMillis()),getResources().getDisplayMetrics().densityDpi); }
相关推荐
Android 图片添加水印的实现方法 实现效果图: 手机端打水印(文字和图片)使用的是Bitmap、Matrix和Canvas类的一些方法, 可以实现拉伸、旋转、位移等等效果。 原理很简单, 就是在画布Canvas上绘制图形、图片、...
实现View的拖拽,放大,缩小、保存至本地。
Android为图片加图片logo水印,可以加文字水印,左上角,右上角,中间,左下角,右下角
android图片加水印效果.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
android添加图片水印,动态添加
主要介绍了Android图片添加水印图片并把图片保存到文件存储的实现代码,代码简单易懂,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
C#开发Android实现拍照加水印,以及视频录制,预览实例
Android 调用系统相机/相册 获取照片 在照片上添加文字水印
在android中给图片添加水印文字和图片
Android图片压缩、加水印 http://blog.csdn.net/zivensonice/article/details/51462470
xamarin android相机使用实例源码及水印菜单,具体实例代码请下载
本例是通过自定义imageview实现自动添加水印的,这样不仅简单,而且可以增强代码可读性,就跟使用原生的imageview一样简单哦。
现在我们想要往图片上打上水印,该水印应符合这样的需求的: 1. 支持logo+文字; 2. 文字信息支持多行展示; 3. 用户可以选择水印在图片上的生成位置(左上、右上、右下和左下)。 现在提供这样的一种思路去实现这一...
之前有人反馈之前上传的下载不了,我再次上传一次,如果有问题及时给我发邮件,或者可以关注一下我,给我发私信,咱们互相学习!(android端代码,FFmpeg实现为视频加水印, 邮箱:1213236113@qq.com)
给图片加水印,代码所提供的方法可以和照相功能结合起来想水印相机一样拍照 合成水印照片
Android程序,从相机、相册获取图片、进行图片裁剪、添加水印(仿食色水印)、添加标签(仿nice标签)
该资源主要是参考博文 http://blog.csdn.net/eastmount/article/details/40536247,主要是Android触屏setOnTouchListener实现图片缩放、移动、绘制和添加水印,有四个按钮.点击“打开”从相册中加载一张图片,点击...
Android添加静态图片录像水印
本项目是一个图片处理的综合例子源码,实现了图片的旋转,缩放,加盖水印,透明,倾斜,扭曲用到的图片是使用httpclient 实现在线图片的下载展示,并实现图片处理。如果,网络图片不存在了,请在代码中修改图片路径...