Android开发:给图片添加水印

添加水印的方法:

 private Bitmap addTimeFlag(Bitmap src){  

         // 获取原始图片与水印图片的宽与高    
        int w = src.getWidth();    
        int h = src.getHeight();    
        Bitmap newBitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);    
        Canvas mCanvas = new Canvas(newBitmap);    
        // 往位图中开始画入src原始图片    
        mCanvas.drawBitmap(src, 0, 0, null);   
        //添加文字  
        Paint textPaint = new Paint();    
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");    
        String time = sdf.format(new Date(System.currentTimeMillis()));    
        textPaint.setColor(Color.RED) ;  
        textPaint.setTextSize(100);   
        String familyName = "宋体";    
//        Typeface typeface = Typeface.create(familyName,    
//                Typeface.BOLD_ITALIC);    
//        textPaint.setTypeface(typeface);    
//        textPaint.setTextAlign(Align.CENTER);    
          
        mCanvas.drawText(time, (float)(w*1)/7, (float)(h*14)/15, textPaint);   
        mCanvas.save(Canvas.ALL_SAVE_FLAG);    
        mCanvas.restore();    
        return newBitmap ;  

    }  

学习累了,休息一下吧!关注微信公众号“休闲1刻”,或扫描下方二维码,休闲段子等着你哦~




猜你喜欢

转载自blog.csdn.net/android157/article/details/80453869