增加分配给应用程序内存 [英] increase the memory allocated to application

查看:519
本文介绍了增加分配给应用程序内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试显示由摄像机拍摄的图像,并在应用中显示它们。当我把低分辨率图像(比如100KB的大小),我与开关位图显示没有问题,当我带他们在高分辨率(1.5MB)利弊,应用程序崩溃与例外

 错误java.lang.OutOfMemoryError。

这恰好是我的智能手机(三星Galaxy SII,SIII银河)是全部下架。
现在我手动解决通过降低照片的质量和尺寸,但考虑摄像机随分辨率的演变,这个问题很可能更频繁地出现。
有没有一个永久性的解决方案,以增加分配给我的Andr​​oid应用程序,而不在设备上人工干预,并在code中的内存呢?

图像存储在位图格式

  //创建映像
乌里domuri1ContentValues​​ CV =新ContentValues​​();
cv.remove(101);
。domuri1 = getContentResolver()插入(Media.EXTERNAL_CONTENT _URI,CV);
文件domthumb1 =新的文件(domuri1.toString(),文件名1);//增量照片APPARATE
意向意图=新意图(android.media.action.IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,domuri1);
startActivityForResult(意向,100);//保存图像
ContentResolver的CR = getContentResolver();
bitmap1 = MediaStore.Images.Media.getBitmap(CR,domuri1);
imageView.setImageBitmap(bitmap1);


解决方案

对于正常的应用程序的默认内存值是16MB,并可以使用的android:largeHeap =真正的(这可能会增加内存高达64MB)在 applicattion 标签内的manifiest文件。你可以通过分配给您的内存值
 <一href=\"http://developer.android.com/reference/android/app/ActivityManager.html#getMemoryClass%28%29\">ActivityManager.getMemoryClass()和<一个href=\"http://developer.android.com/reference/android/app/ActivityManager.html#getLargeMemoryClass%28%29\">ActivityManager.getLargeMemoryClass().

即使你问 largeHeap ,如果在所有应用程序需要它的Andr​​oid将只分配更多的内存。

I try to display images taken by the camera and display them in the application. When I take low-resolution images (say 100kB in size), I have no problems with the switch to bitmapped display, cons when I take them in high resolution (1.5MB), the application crashes with the exception

  Error java.lang.OutOfMemoryError. 

it happens to be on my smartphone (Samsung Galaxy SII, SIII Galaxy) is on all the shelves. For now I solved manually by lowering the quality and size of the photos but, given the evolution of cameras with increasing resolution, this problem is likely to arise more often. Is there not a permanent solution to increase the memory allocated to my application for Android without manual intervention on the device and in the code?

Images are stored in bitmap format

 //image creation
Uri domuri1

ContentValues cv = new ContentValues();
cv.remove("101");
domuri1 = getContentResolver().insert(Media.EXTERNAL_CONTENT _URI, cv);
File domthumb1 = new File(domuri1.toString(), fileName1);

//increment photo apparate
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT, domuri1);
startActivityForResult(intent, 100);

//images save
ContentResolver cr = getContentResolver();
bitmap1 = MediaStore.Images.Media.getBitmap(cr, domuri1 );
imageView.setImageBitmap(bitmap1);

解决方案

The default memory value for a normal App is 16MB and You can use android:largeHeap="true" (which may increase memory up to 64MB) in your manifiest file inside the applicattion tag. You can get the memory values assigned to you by ActivityManager.getMemoryClass() and ActivityManager.getLargeMemoryClass().

Even if you ask for largeHeap the android will only assign more memory if at all your application needs it.

这篇关于增加分配给应用程序内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆