private Bitmap reSize(Bitmap bitmaporg) {    int widthold = bitmaporg.getWidth();//eg:1024    int heightold = bitmaporg.getHeight();//eg:819    //获取屏幕的宽高    DisplayMetrics dm = new DisplayMetrics();    getWindowManager().getDefaultDisplay().getMetrics(dm);    int screenWidth = dm.widthPixels;  //eg:1440    int screenHeigh = dm.heightPixels;  //eg:2392    float density = dm.density;  // 密度(0.75 / 1.0 / 1.5 //eg: 1dp=3.5px    //int densityDpi = dm.densityDpi;  // 密度DPI120 / 160 / 240    float scale = (float) screenWidth / ((density + 0.2f) * widthold);    Matrix matrix = new Matrix();    if (scale < 1) {        //将大图缩小至适屏        float scaleWidth = (float) scale;        float scaleHeight = (float) scale;        matrix.postScale(scaleWidth, scaleHeight);    } else {        float scaleWidth = 1;        float scaleHeight = 1;        matrix.postScale(scaleWidth, scaleHeight);    }    Log.d("Main", "screenWidth:" + screenWidth);    Log.d("Main", "screenHeight:" + screenHeigh);    Log.d("Main", "widthold:" + widthold);    Log.d("Main", "heightold:" + heightold);    Bitmap bitmapnew = Bitmap.createBitmap(bitmaporg, 0, 0, widthold, heightold, matrix, true);    int widtnew = bitmapnew.getWidth();    int heightnew = bitmapnew.getHeight();    Log.d("Main", "widthnew:" + widtnew);    Log.d("Main", "heightnew:" + heightnew);    return bitmapnew;}

更多相关文章

  1. Android 图片预览模仿朋友圈查看图片效果放大图片,左右滑动 - tra
  2. Android大图片导致内存问题小结
  3. Android开发之如何获取Android手机屏幕的大小(分辨率、密度)
  4. android高效读取大图片 防止OOM
  5. Android - 像素密度和屏幕适配

随机推荐

  1. Android(安卓)全局变量 Application
  2. 转: The System Server in Android
  3. Android(安卓)systrace
  4. Android(安卓)动画 Animation
  5. Android(安卓)Tcp服务器端
  6. Android(安卓)Learning-Application Fund
  7. Android(安卓)NDK下载(r10~r21)
  8. android Media process
  9. vlc for android 官网sample使用
  10. Android(安卓)关闭后台音频播放