Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. // size of the text in the TextView on the ImageView
  2. textSize = topTextView.getTextSize();
  3.  
  4. // area of the ImageView
  5. imageViewArea = ((imageView.getWidth()) * (imageView.getHeight()));
  6.  
  7. // area of the Canvas
  8. canvasArea = ((canvas.getWidth()) * (canvas.getHeight()));
  9.  
  10. // cross multiplication
  11. x = (((textSize)/(imageViewArea)) * (canvasArea));
  12.  
  13. public Bitmap createMeme(ImageView img){
  14. BitmapDrawable bitmapDrawable = ((BitmapDrawable) img.getDrawable());
  15. Bitmap bitmap = bitmapDrawable.getBitmap();
  16. Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
  17.  
  18. String topText = topTextView.getText().toString();
  19. String bottomText = bottomTextView.getText().toString();
  20.  
  21. topText = topText.toUpperCase();
  22. bottomText = bottomText.toUpperCase();
  23.  
  24. Canvas canvas = new Canvas(mutableBitmap);
  25.  
  26. // size of the text in the TextView on the ImageView
  27. textSize = topTextView.getTextSize();
  28.  
  29. // area of the ImageView
  30. imageViewArea = ((imageView.getWidth()) * (imageView.getHeight()));
  31.  
  32. // area of the Canvas
  33. canvasArea = ((canvas.getWidth()) * (canvas.getHeight()));
  34.  
  35. // cross multiplication
  36. x = (((textSize)/(imageViewArea)) * (canvasArea));
  37.  
  38. TextPaint topFillPaint = new TextPaint();
  39. TextPaint bottomFillPaint = new TextPaint();
  40.  
  41. TextPaint topStrokePaint = new TextPaint();
  42. TextPaint bottomStrokePaint = new TextPaint();
  43.  
  44. Typeface typeface = getResources().getFont(R.font.impact);
  45.  
  46. topFillPaint.setColor(Color.WHITE);
  47. topFillPaint.setTextSize(x);
  48. topFillPaint.setTypeface(typeface);
  49.  
  50. topStrokePaint.setStyle(Paint.Style.STROKE);
  51. topStrokePaint.setStrokeWidth(8);
  52. topStrokePaint.setTextSize(x);
  53. topStrokePaint.setColor(Color.BLACK);
  54. topStrokePaint.setTypeface(typeface);
  55.  
  56. bottomFillPaint.setColor(Color.WHITE);
  57. bottomFillPaint.setTextSize(x);
  58. bottomFillPaint.setTypeface(typeface);
  59.  
  60. bottomStrokePaint.setStyle(Paint.Style.STROKE);
  61. bottomStrokePaint.setStrokeWidth(8);
  62. bottomStrokePaint.setColor(Color.BLACK);
  63. bottomStrokePaint.setTextSize(x);
  64. bottomStrokePaint.setTypeface(typeface);
  65.  
  66. StaticLayout topFillLayout = new StaticLayout(topText, topFillPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
  67. 1.0f, 0.0f, false);
  68.  
  69. StaticLayout topStrokeLayout = new StaticLayout(topText, topStrokePaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
  70. 1.0f, 0.0f, false);
  71.  
  72. StaticLayout bottomFillLayout = new StaticLayout(bottomText, bottomFillPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
  73. 1.0f, 0.0f, false);
  74. StaticLayout bottomStrokeLayout = new StaticLayout(bottomText, bottomStrokePaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
  75. 1.0f, 0.0f, false);
  76.  
  77. topFillLayout.draw(canvas);
  78.  
  79. topStrokeLayout.draw(canvas);
  80.  
  81. canvas.translate(0, canvas.getHeight() - 210);
  82. bottomFillLayout.draw(canvas);
  83.  
  84. bottomStrokeLayout.draw(canvas);
  85.  
  86. return mutableBitmap;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement