0

在我的应用程序中,我正在使用相机功能,但是当我使用 5 MP 设备相机单击照片然后在我的构建中使用它然后构建导致 OutOfMemoryError 时,我该如何防止它。当点击图片并按下确定按钮时,我正在使用下面的代码将其带入我的应用程序。

case TAKE_P:
if (resultCode == Activity.RESULT_OK)
     {
                        Uri selectedImage = imageUri;
                        getContentResolver().notifyChange(selectedImage, null);
                        // ImageView imageView = (ImageView)
                        // findViewById(R.id.ImageView);
                        ContentResolver cr = getContentResolver();
                        Bitmap bitmap;
                        try {
                            yourselectedimage = android.provider.MediaStore.Images.Media
                                    .getBitmap(cr, selectedImage);
                            Bitmap newBitmap = Bitmap.createScaledBitmap(
                                    yourselectedimage, width1, height1, true);
                            drawabledata = new BitmapDrawable(newBitmap);
                            ll.setVisibility(View.GONE);
                            //gallery.setImageResource(R.drawable.imagegallery);
                            galleryisclicked = true;
                            if (mCanvasView != null)
                                clearcanvas();
                            fillmenu();
                            // imageView.setImageBitmap(bitmap);
                            // Toast.makeText(this, selectedImage.toString(),
                            // Toast.LENGTH_LONG).show();
                        }
                         catch (OutOfMemoryError e) {
                                Log.i("#############", "###############");
                                Timer t = new Timer();
                                t.schedule(new TimerTask() {
                                    public void run() {
                                        System.gc();
                                        System.gc();
                                    };
                                }, 1000);
                                Toast.makeText(this, "Out of Memory", Toast.LENGTH_SHORT)
                                .show();
                            }catch (Exception e) {
                            Timer t = new Timer();
                            t.schedule(new TimerTask() {
                                public void run() {
                                    System.gc();
                                    System.gc();
                                };
                            }, 1000);

                            Toast.makeText(this, "Reload again", Toast.LENGTH_SHORT)
                                    .show();
                            Log.e("Camera", e.toString());
                        }
                    }
4

0 回答 0