2

我一直在开发一个相机应用程序,它只是将相机拍摄的照片存储在自定义文件夹中。我遇到了一个奇怪的错误,我无法找到重复的问题。虽然我的应用程序按应有的方式拍摄并将图片保存在文件夹中,但这些图像是不可见的。更奇怪的是,存储在 Camera Shots 文件夹(我手机的默认图片存储位置)中的图像副本是可见的。我已经尝试以多种不同的方式修改我的代码,但我仍然得到相同的结果。下面是我的代码。任何帮助将不胜感激!谢谢!

camera.setOnClickListener(new View.OnClickListener() {              
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                     String name = Environment.getExternalStorageDirectory().toString();
                        File mainFolder = new File(name + "/Filename/");    
                            mainFolder.mkdirs();
                            Random generator = new Random();
                            int random = 10000;
                            random = generator.nextInt(random);
                            String fileName = "Image-"+ random +".jpg";
                            File file = new File (mainFolder, fileName);
                            if (file.exists ()) file.delete (); 
                            try {
                                   FileOutputStream stream = new FileOutputStream(file);
                                   bmp.compress(Bitmap.CompressFormat.JPEG, 90, stream);
                                   stream.flush();
                                   stream.close();

                            } catch (Exception e) {
                                   e.printStackTrace();
                            }

                    startActivityForResult(i, cameraData); 
                }

            });
4

1 回答 1

0

我想到了。我错过了URI。以下是遇到此问题的任何人的更新(和工作)代码:

camera.setOnClickListener(new View.OnClickListener() {              
            public void onClick(View v) {
                // TODO Auto-generated method stub

                i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                 String name = Environment.getExternalStorageDirectory().toString();
                    File mainFolder = new File(name + "/Filename/");    
                        mainFolder.mkdirs();
                        Random generator = new Random();
                        int random = 10000;
                        random = generator.nextInt(random);
                        String fileName = "Image-"+ random +".jpg";
                        File file = new File (mainFolder, fileName);
                        Uri uriSavedImage = Uri.fromFile(file);
                        i.putExtra("output", uriSavedImage);

                startActivityForResult(i, cameraData); 
            }

        });
于 2012-12-28T22:33:09.953 回答