1

I have an Android application to show images with viewPager. The images is in fixed size, so in some Android devices they appear with an empty border according to screen size and screen resolution.

Is there and way to resize the image to fit the screen?

It's not possible to put more than one image size in project, because I have more than 500 images.

4

2 回答 2

3
Bitmap scaledBitmap = scaleDown(realImage, MAX_IMAGE_SIZE, true);

缩小方法

public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
        boolean filter) {
    float ratio = Math.min(
            (float) maxImageSize / realImage.getWidth(),
            (float) maxImageSize / realImage.getHeight());
    int width = Math.round((float) ratio * realImage.getWidth());
    int height = Math.round((float) ratio * realImage.getHeight());

    Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
            height, filter);
    return newBitmap;
}
于 2013-10-09T06:52:18.160 回答
3

您应该尝试不同的 scaleTypes 可用。可以在此处找到文档, 并且(我更喜欢)这里是这些 scaleType 外观的非常好的示例集合。

如果您只想拉伸图像并且不关心丢失纵横比,您可能想要使用scaleType: fitXY

于 2013-10-09T07:03:43.950 回答