0

I'm trying to write some text across a bitmap in Android. I've followed several guides and attempted several different code variations but I either get something obscure, a blank screen or the unaltered bitmap. This is the basic idea of what I've been playing around with.

public Bitmap writeOnDrawable(Context gContext, String path, String text) {

    Bitmap bitmap = BitmapFactory.decodeFile(path);

    Bitmap bmOverlay = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_4444);

    Canvas canvas = new Canvas(bmOverlay);

    Paint paint = new Paint();
    paint.setColor(Color.CYAN);
    paint.setTextSize(20);
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);

    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.drawPoint(30, 50, paint);
    canvas.drawText("Text", 33, 53, paint);

    return bmOverlay;
}

I pass this function the variables and then use the returned bitmap by turning it into a BitmapDrawable and making it a background of a layout. This particular version of the function returns only my initial, unaltered bitmap with no "Text" text across it.

I've attempted variations such as copying the original image:

Bitmap drawableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);

Drawing the original image onto the canvas:

canvas.drawBitmap(drawableBitmap, screenHeight, screenWidth, paint);
Twentyonehundred
  • 2,199
  • 2
  • 17
  • 28
  • I think You should follow this link here. http://stackoverflow.com/questions/7320392/how-to-draw-text-on-image – Opiatefuchs Sep 19 '14 at 13:54
  • I've tried implementing solutions like those and end up with the same results. Using a few answers from that particular question I've ended up with the original image returning and a blank image. – Twentyonehundred Sep 19 '14 at 14:18

1 Answers1

2

I solved the problem using android-maps-util library.
add
compile 'com.google.maps.android:android-maps-utils:0.4'
dependency to your gradle file.
Use IconGenerator to create bitmap with text and use it in your BitmapDescriptor to create marker on your map.

ParekhAbhishekN
  • 245
  • 3
  • 14