Resizing TYPE_CUSTOM BufferedImages?

偶尔善良 提交于 2020-01-24 08:48:00

问题


When I read a JPEG from disk, Java sometimes gives me a BufferedImage whose getType() returns TYPE_CUSTOM -- that is, it has a custom color model. I'd like to resize this BufferedImage but I'm not sure how to construct the destination object. Can someone please provide sample code for using the following constructor?

BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable properties)

I would like to create a BufferedImage of the same type as the source, just bigger, and transfer the contents over. Any ideas?


回答1:


Answering my own question, it looks like ImageTypeSpecifier is the answer. Specifically:

  1. Invoke ImageTypeSpecifier.createFromRenderedImage(RenderedImage image) to get back an ImageTypeSpecifier from the image with the custom color model.
  2. Invoke ImageTypeSpecifier.createBufferedImage(int width, int height) on the ImageTypeSpecifier from step 1 to create a new image with the same color model as the original image.


来源:https://stackoverflow.com/questions/429337/resizing-type-custom-bufferedimages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!