2010-10-25 78 views
1

我已经下载了图像从给定的网址,并显示在imageview,它在模拟器中正常工作,但不适用于真正的设备...最新的问题是什么?android上的图像问题

这里我的代码

final String url = urlStr; 
      InputStream inputStream = null; 

      try { 
       inputStream = httpRequest.openHttpConnection(url); 
       if(inputStream!=null) 
       { 
       bitmap = BitmapFactory.decodeStream(inputStream); 
       if(bitmap!=null) 
       { 
       width=bitmap.getWidth(); 
       height=bitmap.getHeight(); 
       int newWidth = 50; 
       int newHeight = 50; 
      // calculate the scale - in this case = 0.4f 
       float scaleWidth = ((float) newWidth)/width; 
       float scaleHeight = ((float) newHeight)/height; 
       // create matrix for the manipulation 
       Matrix matrix = new Matrix(); 
       // resize the bit map 
       matrix.postScale(scaleWidth, scaleHeight); 
       // recreate the new Bitmap 
       resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,width, height, matrix, true); 
       } 
       inputStream.close(); 
      } 
      } 
      catch (IOException e1) 
      { 
       e1.printStackTrace(); 
      } 
      return resizedBitmap; 
+0

在我修复不能简单地粘贴到空应用程序的代码的麻烦之前,“不起作用”是什么意思?强制关闭?缺少图片?图片显示尺寸错误? (Re最后一个你想用resizedBitmap做什么?) – 2010-10-25 14:21:34

+0

它抛出空指针异常.......强制关闭 – Kakey 2010-10-25 16:07:46

回答

1

你为什么不调整它的简单的方法?

Bitmap scaledImage = Bitmap.createScaledBitmap(bitmap, intWidth, intHeight, false);