1

How could I programatically generate an image (ie output_file.png) which is a combination of user input (ie. strings) overlaid on top of another image file?

Hopefully the image below can illustrate it better

Mockup

pondigi
  • 856
  • 2
  • 8
  • 14
  • This might help you out: http://stackoverflow.com/questions/9575746/android-min-2-1-load-images-from-name-string – user3188799 Jan 13 '14 at 03:39

2 Answers2

3

Do you actually need to create an image? Are you trying to save it/share it or just display text overlaying an image?

If you just need to overlay, you can set a textview to overlay the image using a RelativeLayout.

If you want to save and share the image, you should take a look at How to programmatically take a screenshot in Android?

Community
  • 1
  • 1
Patrick Dattilio
  • 1,814
  • 3
  • 21
  • 35
  • If you display this using a TextView overlaying the ImageView, you could have a live preview (even one that updates dynamically as they type.) Pushing a "save" button would then generate the bitmap using the method for which I provided the link. You could popup a preview of this generated bitmap for final confirmation before saving to file if you wanted. – Patrick Dattilio Jan 13 '14 at 04:08
3

To write text directly into a bitmap you can do something similar to the following:

        int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, context.getResources().getDisplayMetrics());
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setSubpixelText(true);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextSize(textSize);  
        paint.setColor(Color.WHITE);

        Canvas myCanvas = new Canvas(myBitmap);
        myCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); 
        myCanvas.drawText(string, x, y, paint);

To write the bitmap to a file you can read the answer to this question here: Convert Bitmap to File

Community
  • 1
  • 1
bracken
  • 374
  • 2
  • 3