title: Converting String to Bitmap (android)
body: <p>Hi I want to convert String to Bitmap and all things are good but I don't know how to set the result Image to fit the text .
  How can I do that ?
  Here is my code:</p>
  
  <pre><code>public Bitmap textAsBitmap(String text, float textSize, float stroke,
                             int color, Typeface typeface) {
  
      TextPaint paint = new TextPaint();
      paint.setColor(color);
      paint.setTextSize(textSize);
      paint.setStrokeWidth(stroke);
      paint.setTypeface(typeface);
  
      paint.setAntiAlias(true);
      paint.setTextAlign(Paint.Align.LEFT);
  
      float baseline = (int) (-paint.ascent() + 3f);
  
      StaticLayout staticLayout = new StaticLayout(text, 0, text.length(),
              paint, 435, android.text.Layout.Alignment.ALIGN_NORMAL, 1.0f,
              1.0f, false);
  
      int linecount = staticLayout.getLineCount();
  
  
  
  
      int height = (int) (baseline + paint.descent() + 3) * linecount + 10;
  
      Bitmap image = Bitmap
              .createBitmap(****MY WIDTH***, height, Bitmap.Config.ARGB_8888);
  
      Canvas canvas = new Canvas(image);
      canvas.drawARGB(0xFF, 0xFF, 0xFF, 0xFF);
  
      staticLayout.draw(canvas);
  
      return image;
  
  }
  </code></pre>
  
  <p>I even tried this but it doesn't work properly:</p>
  
  <pre><code>final Rect bounds = new Rect();
      paint.getTextBounds(text, 0, text.length(), bounds);
  
  
      Bitmap image = Bitmap
              .createBitmap(bounds.width(), height, Bitmap.Config.ARGB_8888);
  </code></pre>
  
  <p>please help!</p>