gpt4 book ai didi

android - CWAC 相机库内存不足

转载 作者:行者123 更新时间:2023-11-29 00:18:51 26 4
gpt4 key购买 nike

我在尝试使用 android 中的 CWAC 库拍照时内存不足。我只是在主要 Activity 中使用一个按钮并即时创建 fragment 。

预览会很好。但是当我点击拍照时,它会因内存不足而崩溃。有人可以建议如何解决这个问题吗?

CameraFragment cameraFragment = new CameraFragment();

setContentView(R.layout.activity_shopping);
//Create the CameraFragment and add it to the layout
//CameraFragment f = new CameraFragment();
getFragmentManager().beginTransaction()
.add(R.id.container, cameraFragment, TAG_CAMERA_FRAGMENT)
.commit();

//Set the CameraHost
SimpleCameraHost.Builder builder=
new SimpleCameraHost.Builder(new SimpleCameraHost(this));

//SimpleCameraHost simpleCameraHost = new SimpleCameraHost(this);
cameraFragment.setHost(builder.useFullBleedPreview(true).build());

takePicture = (Button) findViewById(R.id.buttonPicture);

//Set an onClickListener for a shutter button
findViewById(R.id.buttonPicture).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
takePicture();
}
});

private void takePicture() {
CameraFragment f = (CameraFragment) getFragmentManager().findFragmentByTag(TAG_CAMERA_FRAGMENT);
if (f != null && f.isVisible()) {
PictureTransaction xact=new PictureTransaction(f.getHost());

xact.flashMode(Camera.Parameters.FLASH_MODE_AUTO);
f.takePicture(xact);
}
}

06-30 15:32:10.661 29474-29823/com.aithops.provrum.app E/dalvikvm-heap﹕ Out of memory on a 31961104-byte allocation.
06-30 15:32:10.661 29474-29823/com.aithops.provrum.app I/dalvikvm﹕ "Thread-32873" prio=5 tid=12 RUNNABLE
06-30 15:32:10.661 29474-29823/com.aithops.provrum.app I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0x425fcb40 self=0x5976d688
06-30 15:32:10.661 29474-29823/com.aithops.provrum.app I/dalvikvm﹕ | sysTid=29823 nice=0 sched=0/0 cgrp=apps handle=1501887568
06-30 15:32:10.661 29474-29823/com.aithops.provrum.app I/dalvikvm﹕ | state=R schedstat=( 424041835 31308999 114 ) utm=36 stm=5 core=3
06-30 15:32:10.661 29474-29823/com.aithops.provrum.app I/dalvikvm﹕ at android.graphics.Bitmap.nativeCreate(Native Method)
06-30 15:32:10.666 29474-29823/com.aithops.provrum.app I/dalvikvm﹕ at android.graphics.Bitmap.createBitmap(Bitmap.java:726)
06-30 15:32:10.666 29474-29823/com.aithops.provrum.app I/dalvikvm﹕ at android.graphics.Bitmap.createBitmap(Bitmap.java:703)
06-30 15:32:10.666 29474-29823/com.aithops.provrum.app I/dalvikvm﹕ at android.graphics.Bitmap.createBitmap(Bitmap.java:636)
06-30 15:32:10.666 29474-29823/com.aithops.provrum.app I/dalvikvm﹕ at com.commonsware.cwac.camera.ImageCleanupTask.run(ImageCleanupTask.java:121)
06-30 15:32:10.666 29474-29823/com.aithops.provrum.app I/dalvikvm﹕ [ 06-30 15:32:10.666 29474:29823 W/dalvikvm ]
threadid=12: thread exiting with uncaught exception (group=0x41a33700)
06-30 15:32:10.671 29474-29823/com.aithops.provrum.app E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-32873
java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:726)
at android.graphics.Bitmap.createBitmap(Bitmap.java:703)
at android.graphics.Bitmap.createBitmap(Bitmap.java:636)
at com.commonsware.cwac.camera.ImageCleanupTask.run(ImageCleanupTask.java:121)

最佳答案

这包含在 the documentation 中.使用 android:largeHeap="true" 或让您的 CameraHostmaxPictureCleanupHeapUsage() 返回接近 0.0f 的值>.

关于android - CWAC 相机库内存不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24491406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com