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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.