如何在android中将paint保存到sdcard中

时间:2012-02-20 10:19:34

标签: android android-emulator

在这里,我需要保存我所依赖的Dwan,这些背景和背景都融入了SD卡。尝试了一些方法,但这里只保存背景图像。不保存图片。任何人都建议我。

             public void save() {
               String filename5;
                          Date date = new Date(0);
                   SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMddHHmmss");
                          filename5 =  sdf.format(date);


      try{
        mBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.writingsapce);

             String path = Environment.getExternalStorageDirectory().toString();
                OutputStream fOut = null;
                File file = new File(path, "/DCIM/"+filename5+".jpg");
                    fOut = new FileOutputStream(file);

                mBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
                    fOut.flush();
                    fOut.close();

          MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
        } catch (Exception e) {
            e.printStackTrace();
            }}

1 个答案:

答案 0 :(得分:0)

尝试这个片段,我使用它并且它有效; - )

try {
                FileOutputStream out = new FileOutputStream(filename);
               mBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
         } catch (Exception e) {
                e.printStackTrace();
         }

            String path = Environment.getExternalStorageDirectory().toString();
            OutputStream fOut = null;
            File file1 = new File(path, "FitnessGirl"+Contador+".jpg");
            fOut = new FileOutputStream(file1);

            mBitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut);
            fOut.flush();
            fOut.close();

            MediaStore.Images.Media.insertImage(getContentResolver(),file1.getAbsolutePath(),file1.getName(),file1.getName());