繁体   English   中英

如何根据屏幕分辨率缩放图像?

[英]how to scale image according to screen resolution?

朋友们,

我正在使用以下代码来resizeImage

 private Bitmap resizeImage( final Bitmap image) {
        Bitmap resizedImage = null;
        if(image != null)
        {
        int maxHeight = 80; //actual image height coming from internet
        int maxWidth = 150; //actual image width coming from internet

        int imageHeight = image.getHeight();
        if ( imageHeight > maxHeight )
        imageHeight = maxHeight;
        int imageWidth = (imageHeight*image.getWidth()) / image.getHeight();
        if ( imageWidth > maxWidth ) {
        imageWidth = maxWidth;
        imageHeight = (imageWidth*image.getHeight()) / image.getWidth();
        }
        resizedImage = Bitmap.createScaledBitmap( image, imageWidth, imageHeight, true);
        }
        return resizedImage;
        }

来自互联网。 现在它在高分辨率屏幕上工作正常,但在小屏幕上它没有任何人指导我应该怎么做根据屏幕分辨率显示图像?

Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();

所以你用你的屏幕宽度和高度,你可以根据屏幕分辨率显示图像。

创建三种类型的可绘制文件夹drawable-hdpi,drawable-mdpi,drawable-ldpi。 在这些文件夹中放置具有相同名称的图像差异分辨率。 该应用程序将映射自己。 另一种方法是创建9补丁图像。 9个补丁图像根据分辨率调整自身。 而且你在创建布局时也要小心。 你必须正确设置布局。 屏幕高度和宽度是必要的,以设置屏幕的哪个部分的图像。

谢谢迪帕克

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM