Button for saving image not working (Android studio)

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Jan 24, 2017 3:52:12 PM via Website

I am creating android photo editing app. The button for saving image is not working, Code below. Thanks in advance.
public class MainActivity extends AppCompatActivity {

ImageView buckysImageView;
Drawable buckysFace;
Bitmap bitmapImage;
Bitmap pic;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    buckysImageView = (ImageView) findViewById(R.id.buckysImageView);

Drawable layers[] = new Drawable[2];
layers[0] = ResourcesCompat.getDrawable(getResources(), R.drawable.brick, null);
layers[1] = ResourcesCompat.getDrawable(getResources(), R.drawable.building, null);
LayerDrawable layerDrawable = new LayerDrawable(layers);
buckysImageView.setImageDrawable(layerDrawable);

    final Button button = (Button) findViewById(R.id.savePicture);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
            buckysImageView.buildDrawingCache();
            Bitmap bm=buckysImageView.getDrawingCache();
            MediaStore.Images.Media.insertImage(getContentResolver(), bm, "title", "description");
        }
    });
}

Thanks;