use of com.joliciel.jochre.utils.JochreException in project jochre by urieli.
the class ImageUtils method getImage.
/**
* Get an image from a sql query which selects only the image itself.
*/
public static BufferedImage getImage(NamedParameterJdbcTemplate jt, String sql, MapSqlParameterSource paramSource, String column) {
BufferedImage image = null;
byte[] pixels = jt.query(sql, paramSource, new ResultSetExtractor<byte[]>() {
@Override
public byte[] extractData(ResultSet rs) throws SQLException, DataAccessException {
if (rs.next()) {
byte[] pixels = rs.getBytes("image_image");
return pixels;
} else {
return null;
}
}
});
ByteArrayInputStream is = new ByteArrayInputStream(pixels);
try {
image = ImageIO.read(is);
is.close();
} catch (IOException e) {
throw new JochreException(e);
}
return image;
}
use of com.joliciel.jochre.utils.JochreException in project jochre by urieli.
the class ImageUtils method storeImage.
/**
* Store the image in a MapSqlParameterSource for usage in an insert/update
* query.
*/
public static void storeImage(MapSqlParameterSource paramSource, String varName, BufferedImage image) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ImageIO.write(image, "png", os);
os.flush();
paramSource.addValue(varName, os.toByteArray());
os.close();
} catch (IOException e) {
throw new JochreException(e);
}
}
use of com.joliciel.jochre.utils.JochreException in project jochre by urieli.
the class ImageUtils method getImage.
/**
* Get the image from a previously retrieved ResultSet.
*/
public static BufferedImage getImage(ResultSet rs, String column) throws SQLException {
BufferedImage image = null;
if (rs.getObject(column) != null) {
byte[] imageBytes = rs.getBytes(column);
ByteArrayInputStream is = new ByteArrayInputStream(imageBytes);
try {
image = ImageIO.read(is);
is.close();
} catch (IOException e) {
throw new JochreException(e);
}
}
return image;
}
Aggregations