JPEGImageEncoder don't work in JDK 7

前端 未结 1 639
一向
一向 2021-01-14 20:29

I try to make captcha using JCaptcha Component and i need to encode image in related servlet. So according to JCaptcha Tutorial, I should use JPEGImageEncoder and it\'s not

相关标签:
1条回答
  • 2021-01-14 20:41

    Use ImageIO:

    // Image writer
        ImageWriter imageWriter = (ImageWriter)ImageIO.getImageWritersBySuffix("jpeg").next();
        ImageOutputStream ios = ImageIO.createImageOutputStream(jpegOutputStream);
        imageWriter.setOutput(ios);
        IIOMetadata imageMetaData = imageWriter.getDefaultImageMetadata(new ImageTypeSpecifier(challenge), null);
        imageWriter.write(imageMetaData, new IIOImage(challenge, null, null), null);
    

    This is replacing the deprecated JPEG functions

    0 讨论(0)
提交回复
热议问题