【问题标题】:Appropriate Image size适当的图像尺寸
【发布时间】:2015-12-08 20:24:59
【问题描述】:

我正在制作一个 Android 应用程序。这将使用覆盖屏幕宽度的图像。宽高比应为16:9。图像将通过互联网加载。存储在服务器上的图像的大小应该是多少,以便它必须适合最小的设备到最大的设备。我不想保持非常大的尺寸,因为这会降低性能。

【问题讨论】:

    标签: android image-processing


    【解决方案1】:

    您可以根据此屏幕保留图像,它适用于所有屏幕尺寸。

    Normal xhdpi - 640×960 (1280×1920 in design) 
    

    【讨论】:

      【解决方案2】:

      您可以在以下链接中找到解决方案。 enter link description here

      你可以在这里找到方法

      public static int calculateInSampleSize(
              BitmapFactory.Options options, int reqWidth, int reqHeight) {
      // Raw height and width of image
      final int height = options.outHeight;
      final int width = options.outWidth;
      int inSampleSize = 1;
      
      if (height > reqHeight || width > reqWidth) {
      
          final int halfHeight = height / 2;
          final int halfWidth = width / 2;
      
          // Calculate the largest inSampleSize value that is a power of 2 and keeps both
          // height and width larger than the requested height and width.
          while ((halfHeight / inSampleSize) > reqHeight
                  && (halfWidth / inSampleSize) > reqWidth) {
              inSampleSize *= 2;
          }
      }
      
      return inSampleSize;}
      

      可以这样直接使用

      mImageView.setImageBitmap(
      decodeSampledBitmapFromResource(getResources(), R.id.myimage, 100, 100));
      

      【讨论】:

        猜你喜欢
        • 2018-11-12
        • 2017-05-21
        • 1970-01-01
        • 2019-01-30
        • 2013-02-24
        • 1970-01-01
        • 2016-04-16
        • 1970-01-01
        • 2013-02-10
        相关资源
        最近更新 更多