如何在图像上打印文字? | Android 工作室 | Java
How can I print text on an image? | Android Studio | Java
我希望能够在我的 android 应用中的图像上打印文本。
目前,下面的代码可以实现图文分开分享。
请参考图片查看结果。如何让文字打印在图片上?
请帮帮我。非常感谢。
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
查看下面的代码:
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"));
}
});
我希望能够在我的 android 应用中的图像上打印文本。
目前,下面的代码可以实现图文分开分享。 请参考图片查看结果。如何让文字打印在图片上?
请帮帮我。非常感谢。
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
查看下面的代码:
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"));
}
});