简体   繁体   中英

android studio, how to save on save,change DATA

I have been making paint app it has a save option and load, but every time I save another image go to gallery i want to 'save on save' option too, to load image change and save on it.

the code save:

drawView.setDrawingCacheEnabled(true);
                    //attempt to save
                    String ima= MediaStore.Images.Media.insertImage(
                            getContentResolver(), drawView.getDrawingCache(),
                            UUID.randomUUID().toString() + ".png", "drawing");
                    //feedback
                    if (ima != 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();
                    }
                    drawView.destroyDrawingCache();
                }
                saveDialog.show();

the load code:

Intent i = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

                startActivityForResult(i, RESULT_LOAD_IMAGE);
            }
        });
        saveDialog.show();
    }
}


        @Override
        protected void onActivityResult ( int requestCode, int resultCode, Intent data){
            super.onActivityResult(requestCode, resultCode, data);

            if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
                Uri selectedImage = data.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                 cursor = getContentResolver().query(selectedImage,
                        filePathColumn, null, null, null);
                cursor.moveToFirst();


                columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                temp = cursor.getString(columnIndex);
                cursor.close();



                 a= BitmapFactory.decodeFile(temp);
                Drawable d = new BitmapDrawable(getResources(), a);

                drawView.setBackgroundColor(Color.WHITE);
                drawView.startNew();

                drawView.setBackground(d);

Rather than trying to have a save on save method, perhaps try instead of loading a default image you load the image you would like to edit. The file path exists since you are saving them in the drawable area and you are able to access the images in your drawable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM