Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 适当的图像大小_Android_Image Processing - Fatal编程技术网

Android 适当的图像大小

Android 适当的图像大小,android,image-processing,Android,Image Processing,我正在制作一个Android应用程序。将使用覆盖屏幕宽度的图像。宽高比应为16:9。这些图像将通过互联网加载。服务器上存储的映像的大小应该是多少,以便它必须适合最小的设备到最大的设备。我不想保持很大的尺寸,因为那样会降低性能 您可以在下面的链接中找到解决方案。 在这里你可以找到方法 public static int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight

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

您可以在下面的链接中找到解决方案。

在这里你可以找到方法

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));

您可以根据此屏幕保留图像,它将适用于所有屏幕大小

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