PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 18, 2022

[FIXED] How can I print text on an image? | Android Studio | Java

 September 18, 2022     android, image, java, printing, text     No comments   

Issue

I want to be able to print text on an image in my android app.

Currently, the code below allows the picture and text to be shared separately from each other. Please refer to the picture to see the result. How can I get the text to print on the image?

Please help me out. I would really appreciate.

holder.shareBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        bitmapDrawable = (BitmapDrawable) holder.imageView.getDrawable();// get the from imageview or use your drawable from drawable folder
        bitmap1 = bitmapDrawable.getBitmap();
        String imgBitmapPath= MediaStore.Images.Media.insertImage(context.getContentResolver(),
                bitmap1,"title",null);
        Uri imgBitmapUri=Uri.parse(imgBitmapPath);
        String shareText=paheliItem.getTitle();
        Intent shareIntent=new Intent(Intent.ACTION_SEND);
        shareIntent.setType("*/*");
        shareIntent.putExtra(Intent.EXTRA_STREAM,imgBitmapUri);
        shareIntent.putExtra(Intent.EXTRA_TEXT, shareText);
        context.startActivity(Intent.createChooser(shareIntent,"Share Wallpaper using"));

    }
});

Image- result on clicking shareBtn


Solution

see code below:

private void drawTextOnBitmap(Bitmap bmp, String text, int x, int y, int textColor) {
        Canvas canvas = new Canvas(bmp);

        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(textColor);
        // draw text
        canvas.drawText(text, x, y, paint);
    }


holder.shareBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        bitmapDrawable = (BitmapDrawable) holder.imageView.getDrawable();// get the from imageview or use your drawable from drawable folder
        // draw text on bitmap
        Bitmap bitmap1 = bitmapDrawable.getBitmap();
        drawTextOnBitmap(bitmap1, "YOUR TEXT", 0, 15, Color.RED);


        String imgBitmapPath= MediaStore.Images.Media.insertImage(context.getContentResolver(),
                bitmap1,"title",null);
        Uri imgBitmapUri=Uri.parse(imgBitmapPath);
        String shareText=paheliItem.getTitle();
        Intent shareIntent=new Intent(Intent.ACTION_SEND);
        shareIntent.setType("*/*");
        shareIntent.putExtra(Intent.EXTRA_STREAM,imgBitmapUri);
        shareIntent.putExtra(Intent.EXTRA_TEXT, shareText);
        context.startActivity(Intent.createChooser(shareIntent,"Share Wallpaper using"));

    }
});


Answered By - Phil
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing