开发者

Grails: write BufferedImage into response

开发者 https://www.devze.com 2022-12-22 07:21 出处:网络
I have ImageController with resize method: def resize = { def pht = Photos.findByTypeAndPhotourl(params.type, params.photourl)

I have ImageController with resize method:

def resize = {
    def pht = Photos.findByTypeAndPhotourl(params.type, params.photourl)
    if (pht != null) {
      BufferedImage source = ImageIO.read(new File(pht.photo))
      ImageResizer imageResizer = new ImageResizer()
      BufferedImage result = imageResizer.resize(source, Integer.parseInt(params.width), Integer.parseInt(params.height))
      imageResizer.writePNG(result, params.name)

      re开发者_JS百科nder "OK"
    } else {
      render "Error"
    }
  }

As you can see - it writes BufferedImage instance (resized image) on the disk. But i want to return image in response so resized image will be displayed in browser when user requests resize method(or he will be able to download it). It's smth like file serving problem...

Does it right way to use:

ImageIO.write(result, "png", response.getOutputStream())


Yeah, ImageIO is the way to go

See

Image resize in Grails

0

精彩评论

暂无评论...
验证码 换一张
取 消