图像缩放功能无法正常工作

时间:2013-04-24 10:37:23

标签: android image device scale kernel-density

我正在开发一个复杂的UI设计,它就像圆形滚轮,在圆形轨迹中包含10个图标。我需要根据设备分辨率缩放每个图标。请查看具体的代码段: -

             if (displayWidth<=241) {
      bitmap = scaleBimtap(bitmap, 42, 39);
     }else if (displayWidth<=320) {
      bitmap = scaleBimtap(bitmap, 42, 39);
     }else if (displayWidth<=480) {
      bitmap = scaleBimtap(bitmap, 52, 44); 
     }else{
      bitmap = scaleBimtap(bitmap, 52, 44);
     }
HTC感觉是540X960分辨率设备。所以这里是bitmap = scaleBimtap(bitmap,52,44);必须在这种情况下选择,但这似乎是错误的缩放和图标显示更大。我能做些什么呢。

1 个答案:

答案 0 :(得分:-1)

来自网址的图片

imageView = new(ImageView)findViewById(R.id.myImage);

从Url获​​取图片

 Bitmap originalBitmap = getBitmapFromURL("http://www.chennaionline.com/home.JPG");

getBitmapFromURL方法:

public static Bitmap getBitmapFromURL(String src) {
        try {
            URL url = new URL(src);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;


}
}

设置位图

Bitmap bitmap = Bitmap.createScaledBitmap(originalBitmap, width,
                height, false);

imageView.setImageBitmap(bitmap);

资源文件中的图片

Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();