-1

I have an imageview which displays an first image. I want to draw second smaller image on top of it. I am using canvas to draw the second image but it doesn't appears. Here I want to check if it's second touch on the imageview then let the second image be drawn. Thanks

iv2.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            int action = event.getAction();
            float x = event.getX();
            float y = event.getY();

            int countClicked = countClicked + 1;

            switch (action) {
            case MotionEvent.ACTION_DOWN:
                Canvas c = new Canvas(myBitmap);
                c.drawBitmap(bm, 0, 0, null);
                iv2.setImageBitmap(myBitmap);

                if(countClicked == 2) {
                    c.drawBitmap(secondBitmap, x, y, p)
                }
                break;
            return true;
Jacob Holloway
  • 887
  • 8
  • 24
artist
  • 6,271
  • 8
  • 25
  • 35

2 Answers2

0

Edit:

            Canvas c = new Canvas(myBitmap);
            c.drawBitmap(bm, 0, 0, null);

            if(countClicked == 2) { //Do this before .setImageBitmap
                c.drawBitmap(secondBitmap, x, y, p)
            }

            iv2.setImageBitmap(myBitmap); //This needs to go after you add the second image

It was drawing, but it was drawing after you set the image to the view, so it never shows up.

Jacob Holloway
  • 887
  • 8
  • 24
0

This is how I overlay 2 images together

        // Get your images from their files
        final Bitmap iconL =
            BitmapFactory.decodeResource(ctx.getResources(),
            getResourceID("alm_big", "drawable", ctx));
        final Bitmap bmpCombo =
            iconL.copy(Bitmap.Config.ARGB_8888, true);

        final Bitmap bmpTop =
            BitmapFactory.decodeResource(ctx.getResources(),
            getResourceID(strIcon_Big, "drawable", ctx));

        // Use the canvas to combine them.
        // Start with the first in the constructor.
        final Canvas cnv = new Canvas(bmpCombo);

        // Then draw the second on top of that
        cnv.drawBitmap(bmpTop, 0f, 0f, null);

        // bmpCombo is now a composite of the two.
        bld.setLargeIcon(bmpCombo);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115