0

結果を返すときにビットマップ画像があり、それを SD カードの Photo Art Camera フォルダーに保存したいのですが、保存されません。「写真が正常に保存されませんでした」というトーストが表示されます。

これはコードです:

mSave.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
        File cacheDir;
        Bitmap bitmap = result;

        // String path = Environment.getExternalStorageDirectory().toString();
        OutputStream fOut = null;
        Date d = new Date();

        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
            cacheDir = new File(android.os.Environment.getExternalStorageDirectory(), "Photo Art Camera");
        } else { cacheDir = MainActivity.this.getCacheDir(); }

        if (!cacheDir.exists()) { cacheDir.mkdirs(); }

        File file = new File(cacheDir, "PhotoMarge" + d.getTime() + ".jpg");
        try {
            fOut = new FileOutputStream(file);
            bitmap.compress(CompressFormat.PNG, 150, fOut);
            // getImageBitmap(myurl).compress(Bitmap.CompressFormat.JPEG, 85, fOut);
            fOut.flush();
            fOut.close();

            Toast.makeText(MainActivity.this, "Photo Saved Sucessfully", 500).show();

            // mDialog.dismiss();
            // MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
        }
        catch (FileNotFoundException e) { e.printStackTrace(); }
        catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(MainActivity.this, "Photo Not Saved Sucessfully", 500).show();
        }
    }
});
4

3 に答える 3

2
i removed my misstake from code .Actually i am saving another bitmap instead saving and converting framelayout bitmap
File cacheDir;
                        frame.setDrawingCacheEnabled(true);

                        icon = Bitmap.createBitmap(frame.getDrawingCache());

                        Bitmap bitmap = icon;

                    //  String path = Environment.getExternalStorageDirectory().toString();
                        OutputStream fOut = null;
                        Date d=new Date();

                        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
                            cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"Photo Art Camera");
                        else
                            cacheDir=MainActivity.this.getCacheDir();
                        if(!cacheDir.exists())
                            cacheDir.mkdirs();

                        File file = new File(cacheDir, "PhotoMarge"+d.getTime()+".jpg");
                        try {
                            fOut = new FileOutputStream(file);
                            bitmap.compress(CompressFormat.PNG, 100, fOut);
                            //getImageBitmap(myurl).compress(Bitmap.CompressFormat.JPEG, 85, fOut);
                            fOut.flush();
                            fOut.close();
                            count();
                            Toast.makeText(MainActivity.this, "Photo Saved Sucessfully", 500).show();

                        //  mDialog.dismiss();

                            //MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
                        } catch (FileNotFoundException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            Toast.makeText(MainActivity.this, "Photo Not Saved Sucessfully", 500).show();

                        }


                    }
                });
于 2013-06-20T05:40:14.637 に答える
1

異なる引数で圧縮している場合は、100 または 120 にする必要があります。

OutputStream fOut = new FileOutputStream(output);
merged.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();

Toast.makeText(getApplicationContext(), "Saved", Toast.LENGTH_SHORT).show();

また

  String strMyImagePath = f.getAbsolutePath();
             FileOutputStream fos = null;
             try {
                 fos = new FileOutputStream(f);
                 bitmap.compress(Bitmap.CompressFormat.PNG,70, fos);

                 fos.flush();
                 fos.close();
              //   MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen");
             }catch (FileNotFoundException e) {

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

                 e.printStackTrace();
             }
于 2013-06-19T15:47:10.353 に答える
0
save22.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                File cacheDir;
                Toast.makeText(Main.this, "Photo", 500)
                .show();
                Bitmap icon;
                relativelayout.setDrawingCacheEnabled(true);

                icon = Bitmap.createBitmap(relativelayout.getDrawingCache());
                Bitmap bitmap = icon;
                relativelayout.setDrawingCacheEnabled(false);
                //File mFile1 = Environment.getExternalStorageDirectory();
                Date d=new Date();
                String fileName = d.getTime()+"mg1.jpg";


                File storagePath = (Environment
                        .getExternalStorageDirectory());
                File dest = new File(storagePath + "/CityAppImages");

                if (!dest.exists()) {
                    dest.mkdirs();

                }

                File mFile2 = new File(dest, fileName);
                sdpath= mFile2.getAbsolutePath();

                Log.d("qqqqqqqqqqqqqqqqqqqqqqq", "zzzzzzzz" + sdpath);
                try {
                    FileOutputStream outStream;

                    outStream = new FileOutputStream(mFile2);

                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);

                    outStream.flush();

                    outStream.close();
                    Toast.makeText(Main.this, "Photo Saved Sucessfully", 500)
                    .show();
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {

                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Toast.makeText(Main.this, "Photo Not Saved Sucessfully",
                            500).show();
                }
于 2013-07-23T07:20:08.623 に答える