когда изображения большие, около 157893 в длину, выдается ошибка NullPointVariable .
это код, который я использую:
Код: Выделить всё
import java.lang.*;
import java.sql.*;
import java.io.*;
import oracle.sql.*;
import java.awt.image.BufferedImage;
import java.awt.Image;
import java.awt.Color;
import javax.imageio.ImageIO;
import oracle.jdbc.driver.*;
public class ResizeImage extends Object
{
public static java.sql.Blob resizeBLOB(java.sql.Blob img, int newW, int newH)
{
try
{
byte [] newdata = img.getBytes(1L, (int)img.length());
newdata = scale(newdata, newW, newH);
oracle.jdbc.OracleConnection conn = (oracle.jdbc.OracleConnection)new OracleDriver().defaultConnection();
java.sql.Blob retBlob = conn.createBlob();
try
{
java.io.OutputStream outStr = retBlob.setBinaryStream(0);
outStr.write(newdata, 0, newdata.length);
outStr.flush();
outStr.close();
}
catch (IOException ioe)
{
System.out.println("IO Error trying to write the outputstream.");
ioe.printStackTrace();
}
return retBlob;
}
catch (SQLException ex)
{
System.out.println("SQLException Error.");
ex.printStackTrace();
}
return img;
}
public static byte[] scale(byte[] fileData, int width, int height)
{
double newW;
double newH;
ByteArrayInputStream in = new ByteArrayInputStream(fileData);
try
{
BufferedImage img = ImageIO.read(in);
if(height == 0)
height = 100;
if(width == 0)
width = 100;
//Figure new Width and Height with Aspect Ratio
double imgW = img.getWidth();
double imgH = img.getHeight();
if(imgH>imgW)
{
newW = (imgW/imgH)*width;
newH = height;
}
else
{
newH = (imgH/imgW)*height;
newW = width;
}
Image scaledImage = img.getScaledInstance((int)newW, (int)newH, Image.SCALE_SMOOTH);
BufferedImage imageBuff = new BufferedImage((int)newW, (int)newH, BufferedImage.TYPE_INT_RGB);
imageBuff.getGraphics().drawImage(scaledImage, 0, 0, new Color(0,0,0), null);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ImageIO.write(imageBuff, "jpg", buffer);
return buffer.toByteArray();
}
catch (IOException e)
{
//throw new ApplicationException("IOException in scale");
e.printStackTrace();
}
return fileData;
}
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... 9c-and-12c