我正在编写一个使用多个3D模型的Android应用程序.这种带纹理的模型会占用大量内存.我发现制造商对应用程序可以使用的堆大小设置了限制.例如我的平板电脑三星Galaxy Tab 8.9 P7310可以占用64MB的内存.
有没有办法增加应用程序可以使用的内存大小?
当我写这个问题时,我设法解决了它,所以在这里重复它以造福他人.这是最初的问题:
我创建了一个非常简单的库项目,我想在另一个项目中引用它.我之前没有遇到任何问题,所以不确定为什么这次不工作.我有:
通过项目属性标记库项目.该default.properties文件具有以下设置:android.library=true
在我的其他项目中,通过项目属性添加了对我的库项目的引用.该default.properties文件具有按预期添加的引用,即android.library.reference.1=K:/android_test_ws/applicationRegistrar
引用的库项目的绿色勾选从绿色开始,然后变为红叉.
这意味着图书馆项目肯定存在错误/遗漏,但我不知道是什么.我在这个场合的图书馆项目比我之前创建的图书馆项目简单得多.
大多数时候,在Android上获取OOM是由于使用了太多位图和/或创建大位图.
最近我决定试用JNI,以便通过将数据本身存储在JNI端来避免OOM.
在与JNI搞砸了一段时间后,我在SO上创建了一些帖子,寻求帮助并分享我的知识,现在我决定与你分享更多代码.如果有人有兴趣阅读调查结果或做出贡献,这里有帖子:
这一次,我添加了存储,恢复,裁剪和旋转位图的功能.它应该很容易添加更多选项,如果其他人在这里将自己的代码添加到更有用的功能,我会很高兴.
所以我要展示的代码实际上是合并了我创造的所有东西.
Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
final int width=bitmap.getWidth(),height=bitmap.getHeight();
// store the bitmap in the JNI "world"
final JniBitmapHolder bitmapHolder=new JniBitmapHolder(bitmap);
// no need for the bitmap on the java "world", since the operations are done on the JNI "world"
bitmap.recycle();
// crop a center square from the bitmap, from (0.25,0.25) to (0.75,0.75) of the bitmap.
bitmapHolder.cropBitmap(width/4,height/4,width*3/4,height*3/4);
//rotate the bitmap:
bitmapHolder.rotateBitmapCcw90();
//get the output java bitmap , …Run Code Online (Sandbox Code Playgroud) java-native-interface android bitmap out-of-memory android-ndk
是否有用于以90度为增量旋转JPEG文件的Java库,而不会导致图像质量下降?
我需要用相机拍照,如果取决于图片大小,请先将其旋转,然后再将其保存到图库中.
我正在使用
Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT,uri); startActivityForResult(imageCaptureIntent,IMAGE_CAPTURE);
拍摄照片并将其保存到临时文件中.
然后
位图bmp = BitmapFactory.decodeFile(imagePath);
String str = android.provider.MediaStore.Images.Media.insertImage(cr,bmp,name,description);
保存它.
这是我试图用来旋转位图的代码
Matrix matrix = new Matrix();
matrix.postRotate(180);
Bitmap x = Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,true);
android.provider.MediaStore.Images.Media.insertImage(cr,x,name,description);
问题是我得到一个OutOfMemoryException.
是否有更好的方法来处理位图以避免破坏内存?
〜先谢谢,问候