强制关闭将位图保存到SD卡

时间:2011-12-30 01:49:53

标签: android bitmap save outputstream forceclose

我将这样的位图保存到SD卡。但应用程序部队关闭。这段代码中有错误吗?

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        compositeImageView = (ImageView) this
                .findViewById(R.id.CompositeImageViewj);
        CompositeImageViewText = (ImageView) this
                .findViewById(R.id.CompositeImageViewTextj);

        choosePicture1 = (Button) this.findViewById(R.id.ChoosePictureButton1j);
        choosePicture2 = (Button) this.findViewById(R.id.okj);
        edtext=(EditText)findViewById(R.id.edtextj);
        save=(Button)findViewById(R.id.savej);
        choosePicture1.setOnClickListener(this);
    //  choosePicture2.setOnClickListener(this);
        //save=(Button)findViewById(R.id.savej);
         final Resources r = this.getResources();
        choosePicture2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String ok=edtext.getText().toString();
                edtext.setCursorVisible(false);
                edtext.buildDrawingCache();
                Bitmap bmp = Bitmap.createBitmap(edtext.getDrawingCache());



                System.out.println("ashish"+edtext.getText().toString());

                    Bitmap bm = BitmapFactory.decodeResource(r, R.drawable.balloon_overlay_focusedj);
                     bmw=combineImages( bm,bmp);
                  CompositeImageViewText.setImageBitmap(bmw);
            //  showDialog(TIME_PICKER_DIALOG); 
            }
        }); 

        //save

save.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                bmf=combineImagesf( bmp1,bmw );

                ContentValues contentValues = new ContentValues(3);
                contentValues.put(Media.DISPLAY_NAME, "Draw On Me");

                Uri imageFileUri = getContentResolver().insert(
                        Media.EXTERNAL_CONTENT_URI, contentValues);

                try {
                    OutputStream imageFileOS = getContentResolver()
                            .openOutputStream(imageFileUri);

                    bmf
                            .compress(CompressFormat.JPEG, 90, imageFileOS);



                } catch (FileNotFoundException e) {
                    Log.v("EXCEPTION", e.getMessage());
                }


            }
}); 

0 个答案:

没有答案