|
效果图
代码中的图标
- /**
- * 二维码商品
- * number origPrice 原价
- * number price 券后价
- * number couponPrice 优惠券金额
- * string title 商品标题
- * string picurl 商品图片网址
- * string qrtext 二维码文字
- * return string 生成的临时海报地址
- **/
- qrGoods = function(origPrice,price,couponPrice,title,picurl,qrtext){
- import gdip
- import qrencode.bitmap
-
- //白背景画布
- var qrGoods = gdip.bitmap(750,1334)
- var canvas = gdip.graphics(qrGoods).clear(0xFFFFFFFF)
- //消除锯齿
- canvas.smoothingMode = 4
- //平滑处理
- canvas.textRenderingHint = 3
-
- //笔刷字体
- var family = gdip.family("黑体-简")
- //绘制商品标题
- canvas.drawString(title,family.createFont(32),::RECTF(60,80,633),,gdip.solidBrush(0xFF323232))
-
- //下载并绘制商品图
- var pic = gdip.image( whttp.get(picurl) )
- canvas.drawImageRect(pic, 60, 215, 633, 633)
-
- //绘制券后价
- var cred = gdip.solidBrush(0xFFFD2624)
- canvas.drawString("券后价",family.createFont(35),::RECTF(60,900),,cred)
- canvas.drawString("¥",family.createFont(35,1),::RECTF(175,900),,cred)
- canvas.drawString(tostring(price),family.createFont(50,1),::RECTF(210,885),,cred)
-
- //绘制原价
- var cgray = gdip.solidBrush(0xFF979797)
- canvas.drawString("原价 ¥",family.createFont(25),::RECTF(60,970),,cgray)
- canvas.drawString(tostring(origPrice),family.createFont(35,8),::RECTF(139,960),,cgray)
-
- //绘制优惠券
- var pic = gdip.image("\res\qrico.png")
- canvas.drawImageRect(pic, 515, 880, 180, 70)
- var cwhite = gdip.solidBrush(0xFFFFFFFF)
- var x1 = 510
- var x2 = 520
- if(couponPrice <100){
- x1 = 535
- x2 = 555
- }elseif(couponPrice <1000){
- x1 = 520
- x2 = 540
- }
- canvas.drawString("¥",family.createFont(25),::RECTF(x1,905),,cwhite)
- canvas.drawString(tostring(couponPrice),family.createFont(50,1),::RECTF(x2,885),,cwhite)
-
- //绘制二维码
- var qr = qrencode.bitmap(qrtext,2,2).copyBitmap(170)
- canvas.drawImageRect(qr, 515, 1075, 170, 170)
-
- //绘制提示文字
- canvas.drawString("新品生活-少花钱,多生钱",family.createFont(28),::RECTF(170,1140),,gdip.solidBrush(0xFF666666))
- canvas.drawString("长按图片,扫码领取优惠券",family.createFont(23),::RECTF(210,1200),,cgray)
- //保存
- var tmp = io.tmpname() +".jpg"
- qrGoods.save(tmp, 90)
-
- return tmp
- }
复制代码 |
|