简体   繁体   English

Titanium Android:图像和内存

[英]Titanium Android: Images and Memory

I'm having problems with using images in both the Android emulator and the Galaxy S2. 我在Android模拟器和Galaxy S2中使用图片时遇到问题。 I'm not writing natively I'm using Titanium. 我不是在写本机,而是在使用Titanium。

If I comment out any references to images in my app, it runs perfectly. 如果我在我的应用程序中注释掉对图像的任何引用,它将完美运行。 I'm have checked for memory leaks and found none. 我已经检查了内存泄漏,却没有发现。

The error I get in the console is: 我在控制台中得到的错误是:

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

The app runs perfectly in iOS, are there any tips to better handle image management with Titanium and Android? 该应用程序可在iOS上完美运行,有没有技巧可以更好地使用Titanium和Android处理图像管理?

SDK: 1.8.2 Runtime: V8 SDK:1.8.2运行时:V8

This is due to memory issue with emulator. 这是由于模拟器的内存问题。 The simplest solution is to add below lines in tiapp.xml file 最简单的解决方案是在tiapp.xml文件中添加以下行

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

Well This is not Titanium Concerned.Because Android doesn't allow High Resolution Files or large weight Images from the Gallery or externalStorage.So You must use the Compressed Images or resized image. 嗯,这与Titanium有关,因为Android不允许来自Gallery或externalStorage的高分辨率文件或大重量图像,因此您必须使用压缩图像或调整大小的图像。

Following Code might help You.Best of Luck... 遵循以下代码可能会对您有所帮助。

        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();
                    }
                }
            }   
        }

I have solved this problem by adding the following code to tiapp.xml 我通过将以下代码添加到tiapp.xml中解决了此问题

<application android:largeHeap="true">

View example under "Requesting a large heap from Dalvik" in the following url: 在以下URL中的“从Dalvik请求大堆”下查看示例:

https://docs.axway.com/bundle/Titanium_SDK_allOS_en/page/tiapp_xml_and_timodule_xml_reference.html#tiapp.xmlandtimodule.xmlReference-Androidspecificapplicationproperties https://docs.axway.com/bundle/Titanium_SDK_allOS_en/page/tiapp_xml_and_timodule_xml_reference.html#tiapp.xmlandtimodule.xmlReference-Androidspecificapplicationproperties

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM