2013-03-20 20 views
0

我开发了一个Android设备应用程序,可将图像从设备库上传到服务器。它可以很好地工作于其他设备期望Galaxy S3。我的Galaxy S2工作正常,但S2和S3的果冻豆相同。将图像上传到Galaxy S3的服务器崩溃,但对其他设备正常工作

在S3上传过程中,图片应用程序崩溃。不知道什么是错的?下面是上传图片的代码:

if (selectedImagePath.length() != 0) { 

      // get data from page 

      try 
      { 

       BitmapFactory.Options opts=new BitmapFactory.Options(); 
       opts.inSampleSize = 4; 

       Bitmap bitmapOrg = BitmapFactory.decodeFile(selectedImagePath,opts); 

       System.gc(); 

       ByteArrayOutputStream bao = new ByteArrayOutputStream(); 


       // Resize the image 
       double width = bitmapOrg.getWidth(); 
       double height = bitmapOrg.getHeight(); 
       double ratio = 300/width; 
       int newheight = (int) (ratio * height); 

       // System.out.println("———-width" + width); 
       // System.out.println("———-height" + height); 

       bitmapOrg = Bitmap.createScaledBitmap(bitmapOrg,400, 
         newheight, true); // 400 chilo age 

       // Here you can define .PNG as well 
       bitmapOrg.compress(Bitmap.CompressFormat.JPEG,75, bao); 

       byte[] ba = bao.toByteArray(); 
       String ba1 = ImageConverter.encodeBytes(ba); 

       // System.out.println("uploading image now ——–” + ba1); 

       ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
       nameValuePairs.add(new BasicNameValuePair("image", ba1)); 

       nameValuePairs.add(new BasicNameValuePair("event_id", 
         Integer.toString(taskEntity.getEventId()))); 
       nameValuePairs.add(new BasicNameValuePair("title", title)); 
       nameValuePairs.add(new BasicNameValuePair("description", 
         description)); 
       nameValuePairs.add(new BasicNameValuePair("urgent", Integer 
         .toString(urgentAttention))); 
       nameValuePairs.add(new BasicNameValuePair("sendtime", 
         convertedtime)); 

       try { 

        HttpClient httpclient = new DefaultHttpClient(); 
        HttpPost httppost = new HttpPost(
          AppSettings.SERVER_ADDRESS+"upload_image.php"); 
        httppost.setEntity(new UrlEncodedFormEntity(
          nameValuePairs)); 

        HttpResponse response = httpclient.execute(httppost); 
        HttpEntity entity = response.getEntity(); 

        // print responce 
        outPut = EntityUtils.toString(entity); 
        Log.i("GET RESPONSE—-", outPut); 

        // is = entity.getContent(); 
        Log.e("log_tag ******", "good connection"); 

        bitmapOrg.recycle(); 


       } catch (Exception e) { 
        Log.e("log_tag ******", 
          "Error in http connection " + e.toString()); 
       } 

      } 
      catch(Exception e) 
      { 
       e.printStackTrace(); 
      } 

     } 

回答

1

您没有说明您收到了什么错误,而是因为你的问题是特定于银河S3我猜这是一个OutOfMemoryError。相对于其屏幕尺寸,S3倾向于具有小应用程序堆,因此位图存储有点紧张。

尝试使用:

opts.inPurgeable = true; 
opts.inInputShareable = true; 

inPurgeable将分配在不同的堆的位图,并允许其数据在内存压力下被丢弃,而无需等待垃圾收集器。 inInput可分配将允许位图从指定的输入重新解码,以防在完成之前将其清除。尽可能经常使用这两个选项是一种很好的做法。请记住,使用inInputShareable时,正在解码的数据不能更改或丢弃,因为位图可能需要重新使用它。

+0

谢谢,解决了。 – arefin 2013-03-21 20:11:36

相关问题