public static Drawable getScaleNinePatchDrawable(int resId) {        Activity mContext = WaWaSystem.getActivity();        int standardBmpHeight = 413;        BitmapFactory.Options optDecodeBounds = new BitmapFactory.Options();        optDecodeBounds.inJustDecodeBounds = true;        InputStream isDecodeBounds = mContext.getResources().openRawResource(                resId);        BitmapFactory.decodeStream(isDecodeBounds, null, optDecodeBounds);        System.out.println("原始图片高度:" + optDecodeBounds.outHeight + ",原始图片宽度:"                + optDecodeBounds.outWidth);        Rect padding = new Rect();        BitmapFactory.Options opt = new BitmapFactory.Options();        opt.inPreferredConfig = Bitmap.Config.ARGB_8888;        opt.inPurgeable = true;        opt.inInputShareable = true;        opt.inTargetDensity = mContext.getResources().getDisplayMetrics().densityDpi;        float heightScalePX = ((Activity) mContext).getWindowManager()                .getDefaultDisplay().getHeight()/480f;        opt.inDensity = (int) (opt.inTargetDensity / (heightScalePX * ((float) standardBmpHeight / optDecodeBounds.outHeight)));        InputStream is = mContext.getResources().openRawResource(resId);        Bitmap newBmp = BitmapFactory.decodeStream(is, padding, opt);        newBmp.setDensity(mContext.getResources().getDisplayMetrics().densityDpi);        if (newBmp.getNinePatchChunk() == null || padding == null) {            System.out.println("BitmapDrawable");            return new BitmapDrawable(mContext.getResources(), newBmp);        } else {            System.out.println("NinePatchDrawable");            return new NinePatchDrawable(mContext.getResources(), newBmp,                    newBmp.getNinePatchChunk(), padding, String.valueOf(resId));        }    }


更多相关文章

  1. android保存预览图片
  2. android 拖拽图片
  3. QQ侧滑删除分享(工具类)
  4. android 布局权重问题(最近布局经常坑爹)
  5. Android之如何获取视频或者图片的缩略图
  6. android 获取WebView的网页高度
  7. Android(安卓)3D图片切换
  8. android 多点触摸 实现图片缩放 Image Zoom
  9. android 根据TextView宽度 自动缩小字体大小 以适应其宽度

随机推荐

  1. Day03
  2. 第三部分:Android 应用程序接口指南---第
  3. android 关于listview item设置高度的问
  4. Android Sensor传感器系统架构初探
  5. USB选择PTP功能时,如何同时显示内置、外置
  6. 初识Android
  7. Android智能电视应用程序开发浅谈(一)
  8. Linux与Android的关系
  9. android默认系统日期、时间、时区更改
  10. android 上面js java数据互传