How do you create a thumbnail image out of a JPEG in Java?

后端 未结 13 2335
日久生厌
日久生厌 2020-11-29 16:51

Can someone please help with some code for creating a thumbnail for a JPEG in Java.

I\'m new at this, so a step by step explanation would be appreciated.

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 17:26

    the Java code above (with the scale / getCompatibleImage methods) worked great for me, but when I deployed to a server, it stopped working, because the server had no display associated with it -- anyone else with this problem can fix it by using: BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

    instead of BufferedImage bi = getCompatibleImage(w, h);

    and deleting the getCompatibleImage method

    (later note -- it turns out this works great for most images, but I got a bunch from my companys marketing department that are 32 bit color depth jpeg images, and the library throws an unsupported image format exception for all of those :( -- imagemagick / jmagick are starting to look more appealing)

提交回复
热议问题