类型不匹配;发现:java.awt.image.BufferedImage需要:java.io.File

时间:2014-09-20 07:14:19

标签: java image scala amazon-web-services io

我可以调整图片大小:

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

0 个答案:

没有答案