zoukankan      html  css  js  c++  java
  • Android 编程下背景图片适配工具类

    package cn.sunzn.util;
    
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Matrix;
    
    /**
     * 处理背景图片的一些工具,如放大 缩小...
     */
    public class BgUtil {
    
        /**
         * 使背景图片适应手机屏幕分辨率
         * 
         * @param context        上下文环境
         * @param screenWidth    手机屏幕宽度
         * @param screenHeight   手机屏幕高度
         * @param resId          背景图片资源ID
         * @return               返回一个新的适应手机屏幕分辨率的图片
         */
        public static Bitmap getSuitableBg(Context context, int screenWidth, int screenHeight, int resId) {
            Bitmap bg = BitmapFactory.decodeResource(context.getResources(), resId);
            int bgWidth = bg.getWidth();
            int bgHeight = bg.getHeight();
            float scaleWidth = (float) screenWidth / bgWidth;
            float scaleHeight = (float) screenHeight / bgHeight;
            Matrix matrix = new Matrix();
            matrix.postScale(scaleWidth, scaleHeight);
            Bitmap newBg = Bitmap.createBitmap(bg, 0, 0, bgWidth, bgHeight, matrix, true);
            return newBg;
        }
    }
  • 相关阅读:
    浮动
    导航
    Json
    节点
    评论框
    WebClient 指定出口 IP
    IIS8 下 JS, CSS 等静态文件出现 500 错误
    使用 ffmpeg 转换 mov 视频
    使用 ildasm 和 ilasm 修改程序集的的引用信息
    2020-01-08 工作日记:无题
  • 原文地址:https://www.cnblogs.com/sunzn/p/3542276.html
Copyright © 2011-2022 走看看