2012-03-23 45 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(); 
        } 
       } 
      } 
     }