Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将Blob转换为JPG并更新Blob_Java_Plsql_Toad - Fatal编程技术网

Java 将Blob转换为JPG并更新Blob

Java 将Blob转换为JPG并更新Blob,java,plsql,toad,Java,Plsql,Toad,我试图读入一个blob,将其转换为JPG,然后将其写回通过引用传入的blob,但是当尝试在TOAD中编译时,我在ImageIO.write上遇到了一个错误 CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED BANNADMIN.IMAGE_CONVERTER AS package uk.co.ImageUtil; import javax.imageio.ImageIO; import java.io.File; import java.io.

我试图读入一个blob,将其转换为JPG,然后将其写回通过引用传入的blob,但是当尝试在TOAD中编译时,我在ImageIO.write上遇到了一个错误

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED BANNADMIN.IMAGE_CONVERTER
   AS package uk.co.ImageUtil;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import oracle.sql.*;
import java.io.OutputStream;

public class ImageConverter {
    public static void convertImage(BLOB[] blob) {
       BufferedImage image = null;
       OutputStream outputStream = null;
        try {
            image = ImageIO.read(blob[0].getBinaryStream());

            outputStream = blob[0].setBinaryStream(0);

            ImageIO.write(image, "JPG", outputStream);

        } catch (IOException e) {
            e.printStackTrace();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
        catch(IllegalArgumentException e) {
            e.printStackTrace();
        }
        finally {
            try {
                if (outputStream !== null) {
                    outputStream.flush();
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
/
如何将BuffereImage转换为RenderImage,以便将JPG版本写回Blob

更新:错误消息为

[Error]  (1: 0): IMAGE_CONVERTER:28: cannot find symbol
[Error]  (1: 0): symbol  : method    write(java.awt.image.BufferedImage,java.lang.String,java.lang.Object)
[Error]  (1: 0): location: class javax.imageio.ImageIO
[Error]  (1: 0):             ImageIO.write(image, "jpg", outputStream);
[Error]  (1: 0):                    ^
[Error]  (1: 0): 1 error

原来这是一个简单的错误,ImageIO.write接收了一个RenderImage,这意味着我必须将BuffereImage强制转换为RenderImage,我已经编写了!==而不是在最后一个街区。有关成功编译的内容,请参见下文

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED BANNADMIN.IMAGE_CONVERTER AS package uk.co.ImageUtil;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import oracle.sql.*;
import java.io.OutputStream;
import java.sql.SQLException;

public class ImageConverter {
    /**
      * Take in a BLOB file (specified as an array parameter but we only ever use [0])
      * Read in the binary stream of the BLOB
      * Change the binary stream to jpg
      * Write the binary stream jpg to the BLOB
      * The BLOB parameter is passed in via out - so there is no need to return the BLOB, only edit it
      */
    public static void convertImage(BLOB[] blob) {
       BufferedImage bufferedImage = null;
       OutputStream outputStream = null;
        try {
            bufferedImage = ImageIO.read(blob[0].getBinaryStream());

            outputStream = blob[0].setBinaryStream(0);

            RenderedImage renderedImage = (RenderedImage)bufferedImage;

            ImageIO.write(renderedImage, "JPG", outputStream);

        } catch (IOException e) {
            e.printStackTrace();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
        catch(IllegalArgumentException e) {
            e.printStackTrace();
        }
        finally {
            try {
                if (outputStream != null) {
                    outputStream.flush();
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
/

原来这是一个简单的错误,ImageIO.write接收了一个RenderImage,这意味着我必须将BuffereImage强制转换为RenderImage,我已经编写了!==而不是在最后一个街区。有关成功编译的内容,请参见下文

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED BANNADMIN.IMAGE_CONVERTER AS package uk.co.ImageUtil;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import oracle.sql.*;
import java.io.OutputStream;
import java.sql.SQLException;

public class ImageConverter {
    /**
      * Take in a BLOB file (specified as an array parameter but we only ever use [0])
      * Read in the binary stream of the BLOB
      * Change the binary stream to jpg
      * Write the binary stream jpg to the BLOB
      * The BLOB parameter is passed in via out - so there is no need to return the BLOB, only edit it
      */
    public static void convertImage(BLOB[] blob) {
       BufferedImage bufferedImage = null;
       OutputStream outputStream = null;
        try {
            bufferedImage = ImageIO.read(blob[0].getBinaryStream());

            outputStream = blob[0].setBinaryStream(0);

            RenderedImage renderedImage = (RenderedImage)bufferedImage;

            ImageIO.write(renderedImage, "JPG", outputStream);

        } catch (IOException e) {
            e.printStackTrace();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
        catch(IllegalArgumentException e) {
            e.printStackTrace();
        }
        finally {
            try {
                if (outputStream != null) {
                    outputStream.flush();
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
/

你犯了什么错误?你能把它包括进来吗?编辑并添加到问题中你得到了什么错误?你能把它包括进来吗?编辑并添加到问题中