当前位置:编程学习 > JAVA >>

为图片加水印

 @override<br> public void oncreate(bundle savedinstancestate) {
  super.oncreate(savedinstancestate);
  setcontentview(r.layout.main);
 
 
  imageview iv=(imageview)findviewbyid(r.id.testimageview);
<br>  drawable d=this.getresources().getdrawable(r.drawable.icon);
<br>  bitmap bm=createbitmap(drawabletobitmap(d),drawabletobitmap(this.getresources().getdrawable(r.drawable.bonus_delivery_small)));
<br>  iv.setimagebitmap(bm);<br> }<br>
//drawable转换bitmap<br> public static bitmap drawabletobitmap(drawable drawable) {   <br>        <br>        bitmap bitmap = bitmap   <br>                        .createbitmap(   <br>                                        drawable.getintrinsicwidth(),   <br>                                        drawable.getintrinsicheight(),   <br>                                        drawable.getopacity() != pixelformat.opaque ? bitmap.config.argb_8888   <br>                                                        : bitmap.config.rgb_565);   <br>        canvas canvas = new canvas(bitmap);   <br>        //canvas.setbitmap(bitmap);   <br>        drawable.setbounds(0, 0, drawable.getintrinsicwidth(), drawable.getintrinsicheight());   <br>        drawable.draw(canvas);   <br>        return bitmap;   <br>} 
 
//icon加入水印
 private bitmap createbitmap( bitmap src, bitmap watermark ) <br>    { <br>        string tag = "createbitmap"; <br>        log.d( tag, "create a new bitmap" ); <br>        if( src == null ) <br>        { <br>            return null; <br>        }         int w = src.getwidth(); <br>        int h = src.getheight(); <br>        int ww = watermark.getwidth(); <br>        int wh = watermark.getheight(); <br>        //create the new blank bitmap  <br>        bitmap newb = bitmap.createbitmap( w, h, config.argb_8888 );//创建一个新的和src长度宽度一样的位图 <br>        canvas cv = new canvas( newb ); <br>        //draw src into  <br>        cv.drawbitmap( src, 0, 0, null );//在 0,0坐标开始画入src <br>        //draw watermark into <br>        cv.drawbitmap( watermark, w - ww-6, h - wh-2, null );//在src的右下角画入水印 <br>        //save all clip <br>        cv.save( canvas.all_save_flag );//保存 <br>        //store <br>        cv.restore();//存储 <br>        return newb; <br>    }

作者“tianlanlan”
 

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,