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

后端 未结 13 2349
日久生厌
日久生厌 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条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 17:28

    There are many image processing frameworks available that you can do this with just a few lines. The example below generates the thumbnails in different resolutions (given a width as reference) using Marvin Framework. The three thumbnails were generated in 92 ms.

    input:

    output:

    import static marvin.MarvinPluginCollection.*;
    
    MarvinImage image = MarvinImageIO.loadImage("./res/input.jpg");
    MarvinImage scaledImage = new MarvinImage(1,1);
    
    scale(image, scaledImage, 250);
    MarvinImageIO.saveImage(scaledImage, "./res/output_x250.jpg");
    
    scale(image, scaledImage, 150);
    MarvinImageIO.saveImage(scaledImage, "./res/output_x150.jpg");
    
    scale(image, scaledImage, 50);
    MarvinImageIO.saveImage(scaledImage, "./res/output_x50.jpg");
    

提交回复
热议问题