增加分配给应用程序内存应用程序、内存

由网友(穷追一个梦)分享简介:我尝试显示由摄像机拍摄的图像,并在应用中显示它们。当我把低分辨率图像(比如100KB的大小),我与开关位图显示没有问题,当我带他们在高分辨率(1.5MB)利弊,应用程序崩溃与例外 错误java.lang.OutOfMemoryError。 这恰好是我的智能手机(三星Galaxy SII,SIII银河)是全部下架。现在我...

我尝试显示由摄像机拍摄的图像,并在应用中显示它们。当我把低分辨率图像(比如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文件。你可以通过分配给您的内存值 ActivityManager.getMemoryClass()和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.

阅读全文

相关推荐

最新文章