将编码的基本64图像字符串转换为输入流而不将图像保存到本地文件系统

时间:2017-02-21 06:26:43

标签: java image jpeg

#/**
 * This method is used to convert encoded base 64 image string into inputStream without saving it into file system
 * @param : encodedBase64Image - Contains encoded base 64 image string
 * @return :InputStream 
 *
 */#
  

将64位图像字符串编码到inputStream中,而不将其保存到文件系统中

InputStream getInputStream(final String encodedBase64Image) {
        long mediaId
        // create a buffered image
        BufferedImage image = null
        byte[] imageByte;
        imageByte = EncodingGroovyMethods.decodeBase64(encodedBase64Image) // Coverting encoded image string into byte array
        ByteArrayInputStream bis = new ByteArrayInputStream(imageByte)
        image = ImageIO.read(bis)
        RenderedImage rImage = (RenderedImage) image; // forming rendered image
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ImageIO.write(rImage, "jpg", os); // JPEG Image is formed in OutputStream
        InputStream fis = new ByteArrayInputStream(os.toByteArray()); /* OutputStream into Inputstream */
        return InputStream
    }
  

将64位图像字符串编码到inputStream中,而不将其保存到文件系统中

0 个答案:

没有答案