サーブレットで AsyncScalr を使用していくつかの大きな画像 (~ 10-15 メガバイト) を縮小していますが、実際のサイズ変更プロセスには約 40 ミリ秒かかりますが、それほど多くはありません。オーバーキルは、ローカル ストレージからイメージを BufferedImage として読み取ることに起因します。そのため、時間はほとんど次のようになります。
画像ファイルの読み取り: 1630ms !! 画像のサイズ変更: 41ms 画像の書き込み: 40ms
以下は私が使用しているコードです。これを行うための最適な方法はありますか?
final FileImageInputStream fileImageInputStream = new FileImageInputStream(file);
BufferedImage bufferedImage = ImageIO.read(fileImageInputStream);
// resize file
Future<BufferedImage> result = AsyncScalr.resize(bufferedImage, Method.SPEED, width, OP_ANTIALIAS, OP_BRIGHTER);
try {
bufferedImage = result.get();
}
catch (InterruptedException e) {
e.printStackTrace();
}
catch (ExecutionException e) {
e.printStackTrace();
}
// Write the image
ImageIO.write(bufferedImage, imageOutput, outputStream);