Skip to content

Instantly share code, notes, and snippets.

@adekunleba
Last active August 29, 2018 11:29
Show Gist options
  • Select an option

  • Save adekunleba/13629fabee5ff82c64b54ba3e5e64a50 to your computer and use it in GitHub Desktop.

Select an option

Save adekunleba/13629fabee5ff82c64b54ba3e5e64a50 to your computer and use it in GitHub Desktop.
def decodeImageString(src: String): Unit = {
//Decode Image String from base64
val imageByte = new ByteArrayInputStream(java.util.Base64.getDecoder.decode(src))
val image = ImageIO.read(imageByte)
val outputFile = new File("Image.jpeg")
ImageIO.write(image, "jpeg", outputFile)
}
def resizeImage(image: BufferedImage, toImgWidth: Int, toImgHeight: Int): BufferedImage = {
if (image.getWidth != toImgWidth || image.getHeight != toImgHeight) {
val newImage = image.getScaledInstance(toImgWidth, toImgHeight, Image.SCALE_SMOOTH) //Return type Image
val newBufferedImage = new BufferedImage(
newImage.getWidth(null),
newImage.getHeight(null), BufferedImage.TYPE_INT_BGR)
newBufferedImage.getGraphics.drawImage(newImage, 0, 0, null)
return newBufferedImage
}
image
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment