Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* this is a simple overlay: one bitmap over another */
- public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2)
- {
- Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(),
- bmp1.getHeight(), bmp1.getConfig());
- Canvas canvas = new Canvas(bmOverlay);
- canvas.drawBitmap(bmp1, new Matrix(), null);
- canvas.drawBitmap(bmp2, new Matrix(), null);
- return bmOverlay;
- }
- /* this is a bit more complex overlay - includes 2 lines of text and a transparent PNG on the background */
- public static Bitmap overlaybottom( Context context, Bitmap bmp1,
- String textLine1, String textLine2 )
- {
- // final bitmap
- Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(),
- bmp1.getHeight(), bmp1.getConfig());
- Canvas canvas = new Canvas(bmOverlay);
- canvas.drawBitmap(bmp1, new Matrix(), null);
- // the second bitmap is a transparent PNG (make it the height you need for 2 lines
- Bitmap bmp2 = BitmapFactory.decodeResource( context.getResources(),
- R.drawable.transparent_png );
- // this is a bit hard-coded but it's just to give an idea...
- boolean singleLine = false;
- boolean doubleLine = false;
- if ( textLine1 != null && textLine1.trim().length() > 0 )
- singleLine = true;
- if ( textLine2 != null && textLine2.trim().length() > 0 )
- doubleLine = true;
- // ** pinto bitmap al pie
- int top = bmp1.getHeight() - bmp2.getHeight();
- int left = 0;
- if ( doubleLine == false )
- top += ( bmp2.getHeight() / 2 );
- canvas.drawBitmap(bmp2, left, top, null);
- if ( singleLine )
- {
- // we have one line of text - set font sizes and paddings
- final int FONT_SIZE = 35;
- final int FONT_SIZE_SMALL = 25;
- final int PADDING = 30;
- Paint paint = new Paint();
- paint.setTextSize( FONT_SIZE );
- paint.setShadowLayer(5, 5, 5, Color.parseColor("#ffffff"));
- paint.setTypeface(Typeface.DEFAULT_BOLD );
- top = top + PADDING;
- left = PADDING / 2;
- // draw the text for the first line
- canvas.drawText( textLine1, left, top, paint );
- if ( doubleLine )
- {
- // we have a second line of text - reset font size
- paint.setTextSize( FONT_SIZE_SMALL );
- paint.setTypeface(Typeface.DEFAULT );
- // with 2 lines of text, our transparent PNG should be higer
- top += paint.getTextSize() + ( PADDING / 2 );
- // finally, draw the text over the transparent PNG
- canvas.drawText( textLine2, left, top, paint );
- }
- }
- return bmOverlay;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement