zoukankan      html  css  js  c++  java
  • 把一张图缩小放到另一张背景图上。

       /**
         *  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);
        }
  • 相关阅读:
    Deepin Linux下安装安卓应用的各种方式
    win下的终端使用指南
    IDEA自定义TODO
    WSL的ssh-agent问题
    MySQL数据类型
    MySQL常用命令.md
    Period 时间坑
    exp/imp管理
    expdp和impdp管理(逻辑导入导出)
    同义词
  • 原文地址:https://www.cnblogs.com/lipeineng/p/6381491.html
Copyright © 2011-2022 走看看