公司一个项目需要把文字和图片 二维码各种合成一张新图 但是分享出去后图片看起来比较模糊求大佬指导, R.mipmap.image_act_back);
int width = 480;//画布大小
int height = 853;//
// mBitmap =Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
mBitmap =BitmapUtil.getBitmap(bitmap,width,height);
canvas = new Canvas(mBitmap);
int x = 30;
int y = 15;
//合成淘宝 (判断是淘宝还是拼多多)
Bitmap bitmap_tb = null;
if (shopType.equals("1")){
//淘宝
bitmap_tb = BitmapFactory.decodeResource(getResources(), R.mipmap.qbs_tb);
}else if (shopType.equals("3")){
bitmap_tb = BitmapFactory.decodeResource(getResources(), R.mipmap.qbs_pdd_order1);
}else if (shopType.equals("4")){
bitmap_tb = BitmapFactory.decodeResource(getResources(), R.mipmap.qbs_wph);
}
Bitmap bitmap2 = BitmapUtil.fitBitmap(bitmap_tb,x);
canvas.drawBitmap(bitmap2,x,y,mPicturePaint2);
//商品标题
TextPaint1.setAntiAlias(true);
TextPaint1.setTextSize(18);
TextPaint1.setColor(getResources().getColor(R.color.black));
String content1 = shopTitle.length()>22? shopTitle.substring(0,22):shopTitle;
int top2 = 30;
canvas.drawText(content1,x+40,x,TextPaint1);
//第二行标题
String content2;
if (shopTitle.length()>34){
content2 = shopTitle.substring(22,35)+"....";
}else {
content2 = shopTitle.length()>22? shopTitle.substring(23):shopTitle;
}
TextPaint1.setAntiAlias(true);
TextPaint1.setTextSize(18);
TextPaint1.setColor(getResources().getColor(R.color.black));
top2 = top2+30;
canvas.drawText(content2,x,top2,TextPaint1);
//券后价格
String content6 = "券后价:";
TextPaint1.setAntiAlias(true);
TextPaint1.setTextSize(24);
TextPaint1.setColor(getResources().getColor(R.color.detail_prise));
top2 = top2+40;
canvas.drawText(content6,x,top2,TextPaint1);
//券后价金额
TextPaint1.setAntiAlias(true);
TextPaint1.setTextSize(30);
TextPaint1.setColor(getResources().getColor(R.color.detail_prise));
String content8 = "¥"+price_after_coupons;
canvas.drawText(content8,x+80,top2,TextPaint1);
// //券背景
// Bitmap bitmap_q = BitmapFactory.decodeResource(getResources(), R.mipmap.qbs_q_back);
// Bitmap bitmap_back = BitmapUtil.fitBitmap(bitmap_q,110);
// canvas.drawBitmap(bitmap_back,330,top2-15,mPicturePaint2);
if (!price_coupons.equals("")){
//券金额
TextPaint1.setAntiAlias(true);
TextPaint1.setTextSize(16);
TextPaint1.setColor(getResources().getColor(R.color.detail_prise));//detail_prise
String content4 = "券¥";
canvas.drawText(content4,340,top2,TextPaint1);
TextPaint1.setAntiAlias(true);
TextPaint1.setTextSize(22);
TextPaint1.setColor(getResources().getColor(R.color.detail_prise));
String content5 = price_coupons+"";
canvas.drawText(content5,340+30,top2,TextPaint1);
}
//原价
TextPaint1.setAntiAlias(true);
TextPaint1.setTextSize(16);
TextPaint1.setColor(getResources().getColor(R.color.theme_black2));
CharSequence content3 = "原价¥";
top2 = top2+40;
canvas.drawText(content3,0,content3.length(),x,top2,TextPaint1);
//原价金额
TextPaint1.setAntiAlias(true);
TextPaint1.setTextSize(26);
TextPaint1.setColor(getResources().getColor(R.color.theme_black2));
CharSequence content7 = price;
canvas.drawText(content7,0,content7.length(),x+60,top2,TextPaint1);
//商品图
// int logo = 0;
// Logger.e(TAG,"图片宽"+resource.getWidth()+"图片高"+resource.getHeight());
Bitmap bitmap_shop = BitmapUtil.fitBitmap(resource,width-50);
Logger.e(TAG,"图片宽"+bitmap_shop.getWidth()+"图片高"+bitmap_shop.getHeight());
top2 = top2+20;
// canvas = new Canvas(mBitmap);
// logo = top2;
canvas.drawBitmap(bitmap_shop,x,top2,mPicturePaint2);
//公司logo
Bitmap bitmap_logo = BitmapFactory.decodeResource(getResources(), R.mipmap.ht_creat_logo);//qbs_creat_logo icon_yfg
Bitmap bitmap_log = BitmapUtil.fitBitmap(bitmap_logo,150);
canvas.drawBitmap(bitmap_log,150,width+top2,mPicturePaint2);
//二维码合成
Bitmap Zxing = ZxingUtils.createQRCode(Wx_Url,300);
int width1 = Zxing.getWidth();
int height1 = Zxing.getHeight();
Matrix matrix = new Matrix();
matrix.postScale(0.35f,0.35f);
Bitmap bitmap1 = Bitmap.createBitmap(Zxing, 0, 0, width1, height1, matrix, true);
Logger.e("二维码宽","二维码宽"+bitmap1.getWidth());
canvas.drawBitmap(bitmap1,353,width-20+top2,mPicturePaint1);
canvas.save();
canvas.restore();
creat_pic.setImageBitmap(mBitmap);