Shailendr singh
Shailendr singh

Reputation: 686

write a custom name on the top of the picture taken by android cam

If this question is repeated then let me know the link of original question because i enable to findout the good link for resolve my current problem.

I am working on android camera I able to take Picture's from my app. But I want to write name on the top of taken picture. i enable to find out how can i resolve this issue. enter image description here

Sorry for i don't have any code for take reference..... any help will be appreciated and i want to pay my thank in advance to all of you.

Upvotes: 1

Views: 115

Answers (1)

Chintan Rathod
Chintan Rathod

Reputation: 26034

Try following code.

public Bitmap drawTextToBitmap(Bitmap bitmap,  String mText) {
    try {

        android.graphics.Bitmap.Config bitmapConfig =   bitmap.getConfig();
        // set default bitmap config if none
        if(bitmapConfig == null) {
          bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
        }
        // resource bitmaps are imutable,
        // so we need to convert it to mutable one
        bitmap = bitmap.copy(bitmapConfig, true);

        Canvas canvas = new Canvas(bitmap);
        // new antialised Paint
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        // text color - #3D3D3D
        paint.setColor(Color.rgb(110,110, 110));
        // text size in pixels
        paint.setTextSize((int) (12 * scale));
        // text shadow
        paint.setShadowLayer(1f, 0f, 1f, Color.DKGRAY);

        // draw text to the Canvas center
        Rect bounds = new Rect();
        paint.getTextBounds(mText, 0, mText.length(), bounds);
        int x = (bitmap.getWidth() - bounds.width())/6;
        int y = (bitmap.getHeight() + bounds.height())/5;

        canvas.drawText(mText, x * scale, y * scale, paint);

        return bitmap;
    } catch (Exception e) {
        return null;
    }

  }

Upvotes: 2

Related Questions