从服务器调整图像大小 [英] Resizing images from server

查看:123
本文介绍了从服务器调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序加载图像,并将其保存到文件中。然后,我用这个code获得可绘制并查看它:

My application load images from server via HTTP and save it into files. Then I use this code to get Drawable and view it:

File f=new File(path);
if(f.exists()) {
    Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
    if(bmp!=null) {
        DisplayMetrics dm = m_activity.getResources().getDisplayMetrics();
        bmp.setDensity(dm.densityDpi);
        Drawable drawable=new BitmapDrawable(context.getResources(), bmp);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        return drawable;
    }
}

这对三星Galaxy S2工作的罚款。但在三星Galaxy S4此图像太小。例如:

It working fine on Samsung Galaxy S2. But on Samsung Galaxy S4 this images too small. For example:

在S2:

在S4:

我需要同样显示它与各显示器的分辨率的所有设备。可能吗?如何实现这一点?

I need to display it equally on all devices with various display's resolution. Is it possible? How to implement this?

推荐答案

我想我可以帮你。我有这个同样的问题我自己。你需要做的是找到这个新的屏幕多少更大的比你的旧人,首先让你的设备的尺寸,并把它们在widthOfStandardDevice和heightOfStandardDevice.Once你知道新的屏幕多少越大那么你的旧,你会做两个乘法器被乘以一切。现在,你可以说设置位图的大小bitmap_width和bitmap_height。

I think I can help you. I had this same kind of problem myself. What you need to do is find how much larger this new screen is than your old one, by first getting the dimensions of your device and putting them in for widthOfStandardDevice and heightOfStandardDevice.Once you know how much larger the new screen is then your old one, you would make two multipliers to multiply everything by. You can now say set the size of the bitmap to bitmap_width and bitmap_height.

DisplayMetrics displaymetrics = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

height = displaymetrics.heightPixels;

width = displaymetrics.widthPixels;

float widthMultiplier = width/widthOfStandardDevice;

float heightMultiplier = height/heightOfStandardDevice;

int bitmap_width = (int)(600 * widthMultiplier);

int bitmap_height = (int)(800 * heightMultiplier);

这篇关于从服务器调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆