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