Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // size of the text in the TextView on the ImageView
- textSize = topTextView.getTextSize();
- // area of the ImageView
- imageViewArea = ((imageView.getWidth()) * (imageView.getHeight()));
- // area of the Canvas
- canvasArea = ((canvas.getWidth()) * (canvas.getHeight()));
- // cross multiplication
- x = (((textSize)/(imageViewArea)) * (canvasArea));
- public Bitmap createMeme(ImageView img){
- BitmapDrawable bitmapDrawable = ((BitmapDrawable) img.getDrawable());
- Bitmap bitmap = bitmapDrawable.getBitmap();
- Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
- String topText = topTextView.getText().toString();
- String bottomText = bottomTextView.getText().toString();
- topText = topText.toUpperCase();
- bottomText = bottomText.toUpperCase();
- Canvas canvas = new Canvas(mutableBitmap);
- // size of the text in the TextView on the ImageView
- textSize = topTextView.getTextSize();
- // area of the ImageView
- imageViewArea = ((imageView.getWidth()) * (imageView.getHeight()));
- // area of the Canvas
- canvasArea = ((canvas.getWidth()) * (canvas.getHeight()));
- // cross multiplication
- x = (((textSize)/(imageViewArea)) * (canvasArea));
- TextPaint topFillPaint = new TextPaint();
- TextPaint bottomFillPaint = new TextPaint();
- TextPaint topStrokePaint = new TextPaint();
- TextPaint bottomStrokePaint = new TextPaint();
- Typeface typeface = getResources().getFont(R.font.impact);
- topFillPaint.setColor(Color.WHITE);
- topFillPaint.setTextSize(x);
- topFillPaint.setTypeface(typeface);
- topStrokePaint.setStyle(Paint.Style.STROKE);
- topStrokePaint.setStrokeWidth(8);
- topStrokePaint.setTextSize(x);
- topStrokePaint.setColor(Color.BLACK);
- topStrokePaint.setTypeface(typeface);
- bottomFillPaint.setColor(Color.WHITE);
- bottomFillPaint.setTextSize(x);
- bottomFillPaint.setTypeface(typeface);
- bottomStrokePaint.setStyle(Paint.Style.STROKE);
- bottomStrokePaint.setStrokeWidth(8);
- bottomStrokePaint.setColor(Color.BLACK);
- bottomStrokePaint.setTextSize(x);
- bottomStrokePaint.setTypeface(typeface);
- StaticLayout topFillLayout = new StaticLayout(topText, topFillPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
- 1.0f, 0.0f, false);
- StaticLayout topStrokeLayout = new StaticLayout(topText, topStrokePaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
- 1.0f, 0.0f, false);
- StaticLayout bottomFillLayout = new StaticLayout(bottomText, bottomFillPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
- 1.0f, 0.0f, false);
- StaticLayout bottomStrokeLayout = new StaticLayout(bottomText, bottomStrokePaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
- 1.0f, 0.0f, false);
- topFillLayout.draw(canvas);
- topStrokeLayout.draw(canvas);
- canvas.translate(0, canvas.getHeight() - 210);
- bottomFillLayout.draw(canvas);
- bottomStrokeLayout.draw(canvas);
- return mutableBitmap;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement