图片水印的生成方法

生成水印的过程。其实分为三个环节:第一,载入原始图片;第二,载入水印图片;第三,保存新的图片。

Java代码  收藏代码
    1. /** 
    2. *     * create the bitmap from a byte array 
    3. *     * 
    4. *     * @param src the bitmap object you want proecss 
    5. *     * @param watermark the water mark above the src 
    6. *     * @return return a bitmap object ,if paramter's length is 0,return null 
    7. *     */  
    8. *    private Bitmap createBitmap( Bitmap src, Bitmap watermark )   
    9. *    {   
    10. *        String tag = "createBitmap";   
    11. *        Log.d( tag, "create a new bitmap" );   
    12. *        if( src == null )   
    13. *        {   
    14. *            return null;   
    15. *        }   
    16. *   
    17. *        int w = src.getWidth();   
    18. *        int h = src.getHeight();   
    19. *        int ww = watermark.getWidth();   
    20. *        int wh = watermark.getHeight();   
    21. *        //create the new blank bitmap   
    22. *        Bitmap newb = Bitmap.createBitmap( w, h, Config.ARGB_8888 );//创建一个新的和SRC长度宽度一样的位图   
    23. *        Canvas cv = new Canvas( newb );   
    24. *        //draw src into   
    25. *        cv.drawBitmap( src, 0, 0, null );//在 0,0坐标开始画入src   
    26. *        //draw watermark into   
    27. *        cv.drawBitmap( watermark, w - ww + 5, h - wh + 5, null );//在src的右下角画入水印   
    28. *        //save all clip   
    29. *        cv.save( Canvas.ALL_SAVE_FLAG );//保存   
    30. *        //store   
    31. *        cv.restore();//存储   
    32. *        return newb;   
    33. *    }  
posted @ 2015-09-18 14:19  visuals  阅读(629)  评论(0编辑  收藏  举报