Bitmap.Config config = bitmap.getConfig(); Bitmap shareBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), config); Canvas canvas = new Canvas(shareBitmap);
canvas.drawBitmap(bitmap, 0, 0, paint);
Paint paint = new Paint(); paint.setColor(Color.BLACK); // 画笔颜色 TextPaint textpaint = new TextPaint(paint); textpaint.setTextSize(textSize); // 文字大小 textpaint.setAntiAlias(true); // 抗锯齿 StaticLayout title_layout = new StaticLayout(title.getText().toString(), textpaint, sourceBitmapWidth, Layout.Alignment.ALIGN_CENTER, 1f, 1f, true);
canvas.translate(0, sourceBitmapHeight); // 移动位置到图片的下面 title_layout.draw(canvas); // 在画布中绘制文字
title_layout.getHeight()
canvas.drawColor(Color.WHITE);
// 拍摄所得的图片为imageBitmap
private Bitmap getShareingBitmap(int textSize) {
Bitmap.Config config = imageBitmap.getConfig();
int sourceBitmapHeight = imageBitmap.getHeight();
int sourceBitmapWidth = imageBitmap.getWidth();
Paint paint = new Paint();
paint.setColor(Color.BLACK); // 画笔颜色
TextPaint textpaint = new TextPaint(paint);
textpaint.setTextSize(textSize); // 文字大小
textpaint.setAntiAlias(true); // 抗锯齿
StaticLayout title_layout = new StaticLayout(title.getText().toString(), textpaint,
sourceBitmapWidth, Layout.Alignment.ALIGN_CENTER, 1f, 1f, true);
StaticLayout desc_layout = new StaticLayout("物品描述:"+description.getText().toString(), textpaint,
sourceBitmapWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, true);
StaticLayout phone_layout = new StaticLayout("联系电话:"+phone.getText().toString(), textpaint,
sourceBitmapWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, true);
Bitmap share_bitmap = Bitmap.createBitmap(sourceBitmapWidth, sourceBitmapHeight +
title_layout.getHeight() + desc_layout.getHeight() + phone_layout.getHeight(),
config);
Canvas canvas = new Canvas(share_bitmap);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(imageBitmap, 0, 0, paint); // 绘制图片
canvas.translate(0, sourceBitmapHeight);
title_layout.draw(canvas);
canvas.translate(0, title_layout.getHeight());
phone_layout.draw(canvas);
canvas.translate(0, phone_layout.getHeight());
desc_layout.draw(canvas);
return share_bitmap;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有