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;
        }
    }
  • 相关阅读:
    信息的概念
    信息管理学基础
    第一章关键术语
    企业的转变
    国外的信息系统概念
    管理信息系统的基本功能
    人机交互设计-评价输入法-课下作业
    《构建之法》一
    27日进度
    26号进度
  • 原文地址:https://www.cnblogs.com/sunzn/p/3542276.html
Copyright © 2011-2022 走看看