How to add a photo to the desired position of the frame?

I'm trying to:

  • Select a photo from the Android gallery (suppose: person.png )
  • Cropping a photo as a rounded image
  • Resize image to 300x300 pixels
  • Then add the modified image ( person.png ) at the top of the frame image ( frame.png ). And the final image will look like this ( final_image.png )
  • Then save the new image ( final_image.png ) to the gallery with the new name.

person.png

person.png

frame.png

frame.png

enter image description here

final_image.png

Here is my demo code for loading an image in a frame or mask.

    ImageView mImageView= (ImageView)findViewById(R.id.imageview_id);
 Bitmap original = BitmapFactory.decodeResource(getResources(),R.drawable.content_image);
 Bitmap mask = BitmapFactory.decodeResource(getResources(),R.drawable.mask);
 Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888);
 Canvas mCanvas = new Canvas(result);
 Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
 paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
 mCanvas.drawBitmap(original, 0, 0, null);
 mCanvas.drawBitmap(mask, 0, 0, paint);
 paint.setXfermode(null);
 mImageView.setImageBitmap(result);
 mImageView.setScaleType(ScaleType.CENTER);
 mImageView.setBackgroundResource(R.drawable.background_frame);
+4

Source: https://habr.com/ru/post/1682570/


All Articles