Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Draw one image over other using the canvas paint and path drawing.
- */
- public Bitmap createMaskedImageInImageCenterRightMug(Drawable back,
- Bitmap bitmapToDrawInTheCenter) {
- Bitmap backgroundBitmap = ((BitmapDrawable) back).getBitmap();
- int hieghtBack = backgroundBitmap.getHeight();
- int widthBack = backgroundBitmap.getWidth();
- int hieghtFront = bitmapToDrawInTheCenter.getHeight();
- int widthFront = bitmapToDrawInTheCenter.getWidth();
- int widthToDrawOnMug = widthBack / 2;
- backgroundBitmap = Bitmap.createScaledBitmap(backgroundBitmap, (int) canvas_width, hieghtBack, true);
- // Create mask
- Bitmap backgroundBitmapMask = Bitmap.createBitmap(backgroundBitmap, 7, 0, (int) (canvas_width / 2), hieghtBack);
- if (widthToDrawOnMug <= widthFront) {
- bitmapToDrawInTheCenter = Bitmap.createBitmap(
- bitmapToDrawInTheCenter, (widthFront * 40) / 100, 0,
- (widthFront * 60) / 100, hieghtFront);
- }
- Bitmap backgroundBitmapScaledMask = Bitmap.createScaledBitmap(
- backgroundBitmapMask, widthToDrawOnMug, hieghtBack - 50, true);
- bitmapToDrawInTheCenter = Bitmap.createScaledBitmap(
- bitmapToDrawInTheCenter, backgroundBitmapScaledMask.getWidth(),
- backgroundBitmapScaledMask.getHeight(), true);
- Bitmap resultBitmap = Bitmap.createBitmap(
- backgroundBitmapScaledMask.getWidth(),
- backgroundBitmapScaledMask.getHeight(),
- backgroundBitmapScaledMask.getConfig());
- Canvas canvas = new Canvas(resultBitmap);
- Paint paint = new Paint();
- paint.setAntiAlias(true);
- paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
- canvas.drawBitmap(backgroundBitmapScaledMask, 0, 0, null);
- canvas.drawBitmap(bitmapToDrawInTheCenter, 0, 0, paint);
- return resultBitmap;
- }
- /**
- * Draw one image over other using the canvas paint and path drawing.
- */
- public Bitmap pasteOverMugForRightMug(Drawable back,
- Bitmap bitmapToDrawInTheCenter) {
- Bitmap backgroundBitmap = ((BitmapDrawable) back).getBitmap();
- Bitmap resultBitmap = Bitmap.createBitmap(backgroundBitmap.getWidth(), backgroundBitmap.getHeight(), backgroundBitmap.getConfig());
- Canvas canvas = new Canvas(resultBitmap);
- canvas.drawBitmap(backgroundBitmap, new Matrix(), null);
- Paint paint = new Paint();
- canvas.drawBitmap(bitmapToDrawInTheCenter, 0, 25, paint);
- return resultBitmap;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement