2012-03-23 32 views
2

我在Android模擬器和Galaxy S2中都使用圖像時遇到問題。我不是在本地編寫我正在使用Titanium。Titanium Android:圖像和內存

如果我在應用程序中註釋掉任何對圖像的引用,它會完美運行。我檢查了內存泄漏,發現沒有。

我在控制檯得到的錯誤是:

I/dalvikvm-heap(1867): Clamp target GC heap from 24.689MB to 24.000MB 
E/GraphicsJNI(1867): VM won't let us allocate 1183156 bytes 
D/dalvikvm(1867): GC_FOR_MALLOC freed <1K, 45% free 4499K/8135K, external 16311K/16603K, paused 48ms 
E/TiDrawableReference(1867): (main) [3335,78053] Unable to load bitmap. Not enough memory: bitmap size exceeds VM budget 
E/TiDrawableReference(1867): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 

該應用程序在iOS的完美運行,是否有任何提示,以更好地處理圖像管理與鈦和Android?

SDK:1.8.2 運行:V8

+0

它不是真的泄漏,它只是手機沒有足夠的內存來顯示大圖片。嘗試你的代碼,但使用一個小圖像,如果可行,那麼你必須將圖片切成塊(獲得Android SDK的示例代碼)。但首先嚐試使用較小的圖像。 – Bigflow 2012-03-23 09:52:44

+0

它看起來是使用backgroundImage fullScreen,我完全改變了屏幕布局,以避免這種情況,並完成工作!謝謝你的提示。 – lookbadgers 2012-03-23 11:49:20

回答

2

這是由於與仿真器的內存問題。最簡單的解決方案是在tiapp.xml文件中添加下面的行

<property name="ti.android.threadstacksize" type="int">131072</property> 
<property name="ti.android.httpclient.maxbuffersize" type="int">131072</property> 
+0

這個問題不僅發生在模擬器上。當從應用製作8MP照片並嘗試調整大小時,我得到了「內存不夠:空」錯誤。 – antongorodezkiy 2015-08-28 23:40:32

0

嗯,這不是鈦Concerned.Because的Android不允許高分辨率文件或從圖庫大重量的圖像或externalStorage.So您必須使用壓縮圖像或調整大小的圖像。

下面的代碼可以幫助You.Best運氣...

 public void onActivityResult(int requestCode, int resultCode, Intent data) { 
      if (resultCode == RESULT_OK) { 
       if (requestCode == SELECT_PICTURE) { 
        Uri selectedImageUri = data.getData(); 
        selectedImagePath = getPath(selectedImageUri); 
        File f = new File(selectedImagePath); 
        bmImg = decodeFile(f);//BitmapFactory.decodeFile(selectedImagePath, options); 
        takePhotoImg.setImageBitmap(imageManipulation.getResizedBitmap(
          bmImg, 240, 160)); 

        ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
        bmImg.compress(Bitmap.CompressFormat.JPEG, 40, bytes); 

        SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss"); 
        timeStamp = s.format(new Date()); 
        File f1 = new File("/sdcard/mysdfile"+ "test"+timeStamp+".jpg"); 
        try { 
         f1.createNewFile(); 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
        //write the bytes in file 
        FileOutputStream fo; 
        try { 
         fo = new FileOutputStream(f1); 
         try { 
          fo.write(bytes.toByteArray()); 
          System.out.println("#########File is being Written=========!!!!!"); 
         } catch (IOException e) { 
          e.printStackTrace(); 
         } 
        } catch (FileNotFoundException e) { 
         e.printStackTrace(); 
        } 
       } 
      } 
     }