添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

一、生成二维码并且将图片转换成为输入流

代码如下(示例):

public BufferedImage addLogo(BufferedImage bufferedImage) {
        Graphics2D graphics2D = bufferedImage.createGraphics();
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        try {
        	//添加二维码 中心的Logo  也可以手动设定Logo位置
            BufferedImage logo = ImageIO.read(new File("D:\\阿葵.jpg"));
            graphics2D.drawImage(logo, width / 5 * 2, height / 5 * 2, width / 5, height / 5, null);
            BasicStroke stroke = new BasicStroke(10, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
            graphics2D.setStroke(stroke);// 设置笔画对象
            //指定弧度的圆角矩形
            RoundRectangle2D.Float round = new RoundRectangle2D.Float(width / 5 * 2, height / 5 * 2, width / 5, height / 5, 20, 20);
            graphics2D.setColor(Color.white);
            graphics2D.draw(round);// 绘制圆弧矩形
            //设置logo 有一道灰色边框
            BasicStroke stroke2 = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
            graphics2D.setStroke(stroke2);// 设置笔画对象
            RoundRectangle2D.Float round2 = new RoundRectangle2D.Float(width / 5 * 2 + 2, height / 5 * 2 + 2, width / 5 - 4, height / 5 - 4, 20, 20);
            graphics2D.setColor(new Color(128, 128, 128));
            graphics2D.draw(round2);// 绘制圆弧矩形
            graphics2D.dispose();
            bufferedImage.flush();
        } catch (IOException e) {
            e.printStackTrace();
        return bufferedImage;
public InputStream createQrCode(int width, int height) {
        boolean flag = false;
        InputStream inputStream = null;
        if (width >= 0 && width <= 500 && height >= 0 && height <= 500) {
            Qrcode qrcode = new Qrcode();
            qrcode.setQrcodeVersion(4);//设置qrcode版本可选1~40
            qrcode.setQrcodeEncodeMode('B');//设置编码类型B表示二进制编码
            qrcode.setQrcodeErrorCorrect('M');//设置纠错类型M,表示15
            BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);//设置bufferImage宽高,色域
            Graphics2D graphics2D = bufferedImage.createGraphics();
            graphics2D.setBackground(Color.white);
            graphics2D.setColor(Color.BLACK);
            graphics2D.clearRect(0, 0, width, height);
            int prefix = 20;//设置偏移量
            try {
                byte[] bytes = content.getBytes("utf-8");
                if (bytes.length > 0 && bytes.length < 1000) {
                    boolean[][] booleans = qrcode.calQrcode(bytes);
                    for (int i = 0; i < booleans.length; i++) {
                        for (int j = 0; j < booleans.length; j++) {
                            if (booleans[i][j]) {
                                //写入图片
                                graphics2D.fillRect(i * 10 + prefix, j * 10 + prefix, 10, 10);
                graphics2D.dispose();//关闭画图
                bufferedImage.flush();//刷新
                //addLogo(bufferedImage);
                //ImageIO.write(bufferedImage, "png", img);
                //ByteArrayOutputStream 是可以讲文件接收到成为一个outputStream
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                //ImageIo.write可以将文件转换成为一个输出流
                ImageIO.write(bufferedImage, "png",os);
                //ByteArrayInputStream  可以通过ByteArrayOutputStream os.toByteArray()输出的比特数组生成一个输出流  输出流->输入流
                inputStream=new ByteArrayInputStream(os.toByteArray());
                return inputStream;
            } catch (IOException e) {
                e.printStackTrace();
        return inputStream;

2.读入数据

代码如下(示例):

data = pd.read_csv(
    'https://labfile.oss.aliyuncs.com/courses/1283/adult.data.csv')
print(data.head())

该处使用的url网络请求的数据。

将BufferedImage转换为InputStream图片直接转换为输入流一、使用步骤1.引入库代码如下(示例):import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport warningswarnings.filterwarnings('ignore')import sslssl._create_default_https_context =
本节书摘来自华章计算机《Java数字图像处理:编程技巧与应用实践》一书中的第2章,第2.1节,作者 贾志刚,更多章节内容可以访问云栖社区“华章计算机”公众号查看。 Java BufferedImage对象及其支持的API操作 第1章我们一起学习了Java中的Graphics图形包基本概念与知识,本章将介绍Java中关于图像文件操作的基本知识。首先...
import sun.misc.BASE64Encoder; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection... public static BufferedImage gardenImage(BufferedImage bi1) { BufferedImage bi2; // 读取图片 bi2 = new BufferedImage(bi1.getWidth(), bi1.getHeight(), BufferedImage.TYPE_INT_RGB); Ellipse2D.Double sha private BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.Ellipse2D; import java.awt.image.B
文章目录前言一、java BufferedImage 转 InputStream1. 描述2. 代码a、逻辑代码b、上传至OSS二、png 图片合成到模板(另一个图片)上时,透明部分变成了黑色1. 案例描述2. 解决 代码都上传到GitHub了,这里仅仅是贴出来主要部分,GitHub传送门:https://github.com/fengfanli/draw_poster_echarts 海报制作的所有博客和一些问题: 文字换行算法详解,传送门: 头像切割成圆形方法详解,传送门: 获取微信二维码详
java生成二维码返回BufferedImage对象,需要转成MultipartFile进行文件上传。 转换程:BufferedImage → InputStream →MultipartFile //得到BufferedImage对象 BufferedImage bufferedImage = JoinTwoImage.testEncode(200, 200, url); //创建一个ByteArrayOutputStream
你可以使用Python中的qrcode库来生成二维码,然后使用Pillow库中的Image模块将生成的二维码保存为图片文件。以下是一个示例代码: ```python import qrcode from PIL import Image # 生成二维码 qr = qrcode.QRCode(version=1, box_size=10, border=5) qr.add_data('https://www.example.com') qr.make(fit=True) # 将二维码保存为图片文件 img = qr.make_image(fill_color="black", back_color="white") img.save('qrcode.png') 在这个示例中,我们首先使用qrcode库生成一个二维码,然后使用Pillow库中的Image模块将其保存为名为"qrcode.png"的图片文件。你可以根据自己的需求修改代码中的参数,例如二维码的大小、边框宽度、填充颜色等。