在按钮上点击sdcard中选定的多个图像

时间:2018-02-23 12:04:34

标签: android

我选择了多个图像并保存在selecteddimages数组中,但我正面临

02-23 16:56:13.362 32078-32078/com.example.manchesterlaptop15.locker E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20180203-WA0002.jpg/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20180203-WA0003.jpg: open failed: ENOTDIR (Not a directory)
02-23 16:56:13.372 32078-32078/com.example.manchesterlaptop15.locker E/AndroidRuntime: FATAL EXCEPTION: main


 public void onClick(View v) {


            final int len = thumbnailsselection.length;
            int cnt = 0;

            String selectImages = "";

            for (int i = 0; i < len; i++) {
                if (thumbnailsselection[i]) {
                    cnt++;
                    selectImages = selectImages + arrPath[i];
                    selecteddimages.add(selectImages);

                }
            }
            if (cnt == 0) {
                Toast.makeText(getActivity().getApplicationContext(),
                        "Please select at least one image",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(getActivity().getApplicationContext(),
                        "You've selected Total " + cnt + " image(s).",
                        Toast.LENGTH_LONG).show();

                Bitmap bitmap;
                OutputStream outst;
                for (int i = 0; i < selecteddimages.size(); i++) {
                    newpth = selecteddimages.get(i);

// bitmap = BitmapFactory.decodeResource(getResources(),Integer.parseInt(newpth));                         bitmap = BitmapFactory.decodeFile(newpth);

                    File filepath = Environment.getExternalStorageDirectory();
                    File dir = new File(filepath.getAbsolutePath() + "/Locker Images");
                    dir.mkdirs();
                    File file = new File(dir, "image.png");
                    Toast.makeText(getActivity().getApplicationContext(),
                            "image saved to sd card",
                            Toast.LENGTH_SHORT).show();
                    try {
                        outst = new FileOutputStream(file);
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outst);
                        outst.flush();
                        outst.close();


                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }

0 个答案:

没有答案