设为首页 加入收藏

TOP

把一张图缩小放到另一张背景图上。
2017-10-12 18:10:43 】 浏览:1694
Tags:张图 缩小 放到 背景

 

 

 

   /**
     *  bitmap 图片缩放到指定大小
     */
    public static Bitmap resizeImage(Bitmap bitmap, int w, int h)
    {
        Bitmap BitmapOrg = bitmap;
        int width = BitmapOrg.getWidth();
        int height = BitmapOrg.getHeight();
        int newWidth = w;
        int newHeight = h;
        
        float scaleWidth = ((float)newWidth) / width;
        float scaleHeight = ((float)newHeight) / height;
        
        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);
        // if you want to rotate the Bitmap
        // matrix.postRotate(45);
        Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true);
        return resizedBitmap;
    }
 
  
   /**
     * 把一张图放到另一张背景图上。
     */
public static Drawable addbackground4onlyicon(Bitmap b1, Bitmap b2,Context mContext)
    {
        if (!b1.isMutable())
        {
            // 设置图片为背景为透明
            b1 = b1.copy(Bitmap.Config.ARGB_8888, true);
        }
        Paint paint = new Paint();
        Canvas canvas = new Canvas(b1);
        
        
        
        canvas.drawBitmap(b2, 17.5f, 17.5f, paint);// 叠加新图b2 (120-85)/2= 17.5
        canvas.save(Canvas.ALL_SAVE_FLAG);
        canvas.restore();
        return  new BitmapDrawable(mContext.getResources(), b1);
    }

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇安卓中Paint类和Canvas类的方法汇.. 下一篇关于我

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目