如何从缓存中将图像保存到设备

时间:2015-12-22 18:08:09

标签: android bitmap save

为什么我不能将绘图缓存保存在设备存储中

else if(view.getId()==R.id.save_btn){
        //save drawing
        AlertDialog.Builder saveDialog = new AlertDialog.Builder(this);

        saveDialog.setTitle("Save drawing");

        saveDialog.setMessage("Save drawing to device Gallery?");

        saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener(){

保存详情

            public void onClick(DialogInterface dialog, int which){
                //save drawing
                drawView.setDrawingCacheEnabled(true);
                String imgSaved = MediaStore.Images.Media.insertImage(
                        getContentResolver(), drawView.getDrawingCache(),
                        UUID.randomUUID().toString()+".png", "drawing");

如果保存图像

                if(imgSaved!=null){
                    Toast savedToast = Toast.makeText(getApplicationContext(), 
                        "Drawing saved to Gallery!", Toast.LENGTH_SHORT);
                    savedToast.show();
                }

如果图像未保存

             else {
                    Toast unsavedToast = Toast.makeText(
                                    getApplicationContext(),
                                    "Oops! Image could not be saved.",
                                    Toast.LENGTH_SHORT);
                            unsavedToast.show();
                        }

错误logcat enter image description here

0 个答案:

没有答案