JAVA 通过URL生成水印图

@Override    public OutputStream watermark1(String ossURL,String logoOsskey,HttpServletResponse response) {        lock.lock();        OutputStream os = null;        InputStream imagestream=null;        //水印        String logoPath = ossService.getossURL(logoOsskey,bucket);        //原图ossURL        try {            os=response.getoutputStream();            imagestream = getimagestream(ossURL);            Image image2 = ImageIO.read(imagestream);            //获取原图信息            int width = image2.getWidth(null);            int height = image2.getHeight(null);            BufferedImage bufferedImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_BGR);            Graphics2D g = bufferedImage.createGraphics();            g.drawImage(image2,width,null);//            //设置多个图片水印            InputStream logo = getimagestream(logoPath);            Image imagelogo = ImageIO.read(logo);            int logoWidth = imagelogo.getWidth(null);            int logoHeight = imagelogo.getHeight(null);            //设置透明度,ALPHA为接口中自定义的值透明度 0.3F            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,ALPHA));            //完成图片旋转30            g.rotate(Math.toradians(0),bufferedImage.getWidth() / 2,bufferedImage.getHeight() / 2);            int x = -width / 2;            int y = -height / 2;            while (x < width * 1.5) {                y = -height / 2;                while (y < height * 1.5) {                    g.drawImage(imagelogo,x,y,null);                    y += logoHeight + 200;                }                x += logoHeight + 300;            }            g.dispose();            Thumbnails.Builder thumbnail = Thumbnails.of(bufferedImage);            thumbnail.size(x,y);            ImageIO.write(thumbnail.asBufferedImage(),"png",os);            //JPEGImageEncoder en = JPEGCodec.createJPEGEncoder(os);            //en.encode(bufferedImage);        } catch (IOException e) {            e.printstacktrace();        } finally {            if (os != null) {                try {                    os.flush();                    os.close();                } catch (IOException e) {                    e.printstacktrace();                }            }            if(imagestream!=null){                try {                    imagestream.close();                }catch (IOException e){                    e.printstacktrace();                }            }        }        lock.unlock();        return os;    }

相关文章

Java中的String是不可变对象 在面向对象及函数编程语言中,不...
String, StringBuffer 和 StringBuilder 可变性 String不可变...
序列化:把对象转换为字节序列的过程称为对象的序列化. 反序...
先说结论,是对象!可以继续往下看 数组是不是对象 什么是对...
为什么浮点数 float 或 double 运算的时候会有精度丢失的风险...
面试题引入 这里引申出一个经典问题,看下面代码 Integer a ...