【发布时间】:2015-12-08 20:24:59
【问题描述】:
我正在制作一个 Android 应用程序。这将使用覆盖屏幕宽度的图像。宽高比应为16:9。图像将通过互联网加载。存储在服务器上的图像的大小应该是多少,以便它必须适合最小的设备到最大的设备。我不想保持非常大的尺寸,因为这会降低性能。
【问题讨论】:
我正在制作一个 Android 应用程序。这将使用覆盖屏幕宽度的图像。宽高比应为16:9。图像将通过互联网加载。存储在服务器上的图像的大小应该是多少,以便它必须适合最小的设备到最大的设备。我不想保持非常大的尺寸,因为这会降低性能。
【问题讨论】:
您可以根据此屏幕保留图像,它适用于所有屏幕尺寸。
Normal xhdpi - 640×960 (1280×1920 in design)
【讨论】:
您可以在以下链接中找到解决方案。 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));
【讨论】: