Java-BufferedImage生成图片(海报)并上传到oss返回URl

java后端通过BufferedImage绘制海报图片,上传到OSS返回图片路径

1.成图如下,楼主随意调试了下写了个模板,废话不多说直接贴代码
在这里插入图片描述
2.service层

// An highlighted block
 */
@Service
public class PosterServiceImpl implements PosterService {
   
    //定义一个图片缓存类
    private BufferedImage image;
    private int imageWidth = 300;  //图片的宽度
    private int imageHeight = 500; //图片的高度
    /*oss的配置项,桶名、路径等*/
    private String endpoint= OSSProperties.ALIYUN_ENDPOINT;
    private String accessKeyId=OSSProperties.ALIYUN_ACCESS_ID;
    private String accessKeySecret=OSSProperties.ALIYUN_ACCESS_KEY;
    private String bucketName=OSSProperties.ALIYUN_BUCKET;

    /**
     *
     * @param productname 产品名称
     * @param originalPrice 原价
     * @param price 现价
     * @param urlone 图片路径
     * @param twourl 图片路径
     * @param threeurl 图片路径
     * @return
     * @throws IOException
     */


    public String graphicsGeneration(String productname, String originalPrice, String price,String urlone,String twourl,String threeurl) throws IOException {
   
        int H_title = 30;     //头部高度
        int H_image =50;
        int H_image_Text =50;
        int H_mainPic = 230;  //轮播广告高度
        int tit_image_text=(H_title+H_image+H_image_Text);
        int shops_2_top = H_title+H_image+H_image_Text+H_mainPic+20;
        //实例化缓存类
        image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
        //设置图片的背景色
        Graphics2D main = image.createGraphics();
        main.setColor(Color.white);
        main.fillRect(0, 0, imageWidth, imageHeight);

        //***********************页面头部
        Graphics title = image.createGraphics();
        //设置区域颜色
        title.setColor(new Color(255, 255, 255));
        //填充区域并确定区域大小位置
        title.fillRect(0, 0, imageWidth, H_title+20);
        //设置字体颜色,先设置颜色,再填充内容
        title.setColor(Color.black);
        //设置字体
        Font titleFont = new Font("黑体", Font.BOLD, 20);
        title.setFont(titleFont);
        title.drawString("驿货·精选
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值