相机在第二次运行时崩溃由于VM内存不足错误

问题描述

| 嗨,我在我的活动中使用这段代码来进行摄影。
public void onActivityResult(int requestCode,int resultCode,Intent data) {
    super.onActivityResult(requestCode,resultCode,data);

    if (requestCode == TAKE_PICTURE_WITH_CAMERA) {
        if (resultCode == Activity.RESULT_OK) {

            // To Write the Images in SDCard
            File f = new File(imgName);
            try {
                Uri capturedImage = Uri
                                 .parse(android.provider.MediaStore.Images.Media
                                     .insertimage(getContentResolver(),f.getAbsolutePath(),null,null));

                Log.i(\"camera\",\"Selected image: \" + capturedImage.toString());

                pic.setimageURI(capturedImage);
            } catch (FileNotFoundException e) {
                e.printstacktrace();
            }
        } else {
            Log.i(\"Camera\",\"Result code was \" + resultCode);
        }
    }
}
我试图将捕获的图像应用于我的
ImageView
。相机第一次拍摄照片并将其设置为
ImageView
。但是,当我第二次运行它时,我的应用程序无法将新捕获的图像设置为
imageView
。从相机意图返回后崩溃。我该如何解决? 任何帮助表示赞赏。     

解决方法

为了避免这种错误,必须先缩放位图。我已经尝试了下面的代码,它工作正常。
bm1=Bitmap.createScaledBitmap(bm,300,true);
                    pic.setImageBitmap(bm1);

                    bm.recycle();
                    bm=null;
    ,当阅读有关相机的信息时,我认为它是硬件。硬件始终使用自己的线程。也许您需要创建一个内存复制映像并由调度程序提供。我不知道您的代码,但是有兴趣收到它来帮助您。 http://blog.lieberlieber.com/2009/07/09/controlinvoke-wpf-style-and-special-bitmapsource-handling/ http://social.msdn.microsoft.com/Forums/zh-CN/wpf/thread/f0c5e590-8bfe-4452-a784-4987af9fce89/