我可以调整图片大小:
def resize(is: java.io.InputStream, maxWidth: Int, maxHeight: Int): List[(BufferedImage, S)] = {
val originalImage = ImageIO.read(is)
val scaledBI = new BufferedImage(maxWidth, maxHeight, BufferedImage.TYPE_3BYTE_BGR)
val g = scaledBI.createGraphics
g.setComposite(AlphaComposite.Src)
g.drawImage(originalImage, 0, 0, maxWidth, maxHeight, null);
g.dispose
List((scaledBI, maxWidth.toString() + "x" + maxHeight.toString()))
} //end resize
request.body.files.map { img =>
val image = resize(new FileInputStream(img.ref.file), 120, 120)
}
但我无法将此保存到AWS S3 这是因为:
amazonS3Client.putObject("path", "image.jpg",image(0)._1)
给我错误:
type mismatch; found : java.awt.image.BufferedImage required: java.io.File
我正在使用Scala 2.10和playframework 2.2