I would like to draw an image (as a family picture i.e.) inside another image (as a frame).
I’m using ImageView to handle this. I can drag my background image around, but the View didn’t draw the front image again.
This is my code for loading two images. mFrontImage is the ‘frame’ and mBackImage is the ‘background’ which we will drag. These lines of code have no issue.
// Create a new bitmap scaled from original bitmap
mFrontImage = Bitmap.createBitmap(bmpTemp, 0, 0, fw, fh, fmatrix, true);
mCanvas = new Canvas(mFrontImage);
mPaint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_OVER));
mCanvas.drawBitmap(mFrontImage, 0, 0, mPaint);
mCanvas.drawBitmap(mBackImage, 0, 0, mPaint);
mImageV = (ImageView) this.findViewById(R.id.image_view);
mImageV.setImageBitmap(mFrontImage);
mImageV.setOnTouchListener(this);
And these are code to handle touch movement:
case MotionEvent.ACTION_DOWN:
downx = event.getX();
downy = event.getY();
_moving = true;
break;
case MotionEvent.ACTION_MOVE:
if (_moving)
{
dx = event.getX() - downx;
dy = event.getY() - downy;
downx = event.getX();
downy = event.getY();
x += dx;
y += dy;
mCanvas.drawColor(Color.TRANSPARENT, Mode.CLEAR);
mCanvas.drawBitmap(mFrontImage, 0, 0, mPaint);
mCanvas.drawBitmap(mBackImage, x, y, mPaint);
mImageEdit.invalidate();
}
break;
case MotionEvent.ACTION_UP:
_moving = false;
break;
The line drawColor will erase the canvas then drawBitmap(mBackImage ~) but not drawBitmap(mFrontImage ~).
What I want to achieve is drawing both mFrontImage at 0, 0 and mBackImage at new position x, y.
I think there’s no way other than create new class implement SurfaceView. I did try and succeed. Here’s my sample code for those who wanted to try similar way.
This code is combined from many sources over internet and myself implementation. You can load both images to the view, then resize/move the background image. I did try rotate but still not finish it yet.
Hope someone will find this useful.