在Imageview上绘制多个位图

时间:2015-04-13 18:04:31

标签: android

我有一个显示第一张图像的imageview。我想在它上面绘制第二个较小的图像。我使用画布绘制第二个图像,但它没有出现。在这里,我想检查它是否是第二次触摸imageview,然后绘制第二个图像。感谢

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;

2 个答案:

答案 0 :(得分:0)

编辑:

            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

它正在绘制,但是在将图像设置为视图后它正在绘制,因此它永远不会显示。

答案 1 :(得分:0)

这就是我将2张图像叠加在一起的方式

        // 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);