How can I save an image with text overlaying it to the Gallery in Android Studio?
<p>We are trying to make an app that lets the user upload an image, write text over it, and then save the new image with the text.</p>

<p>Our current implementation is to use an ImageView to hold the image, then use TextViews to write on top of it.</p>

<p>What would be the best way to save the image as a whole? Below is our current code.</p>

<p>Thanks for the help! :)</p>

<pre><code>protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_generator);

    final EditText topTextInput = (EditText)findViewById(R.id.editTopText);
    final EditText bottomTextInput = (EditText)findViewById(R.id.editBottomText);
    final TextView topTextView = (TextView)findViewById(R.id.topText);
    final TextView bottomTextView = (TextView)findViewById(R.id.bottomText);

    imageView = (ImageView)findViewById(R.id.imageView2);
    Button pickImage = (Button) findViewById(R.id.button2);

    pickImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, SELECT_PHOTO);
        }
    });

    topTextInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            topTextView.setText(topTextInput.getText() + "");
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    bottomTextInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            bottomTextView.setText(bottomTextInput.getText() + "");
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });
}

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

    switch(requestCode) {
        case SELECT_PHOTO:
            if(resultCode == RESULT_OK){
                try {
                    final Uri imageUri = imageReturnedIntent.getData();
                    final InputStream imageStream = getContentResolver().openInputStream(imageUri);
                    final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
                    imageView.setImageBitmap(selectedImage);
                    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }

            }
    }
}
</code></pre>