Import Java.awt.image.bufferedimage;import java.io.file;import Java.io.fileoutputstream;import java.io.IOException ; Import Java.io.outputstream;import Javax.imageio.imageio;import Net.coobird.thumbnailator.thumbnails;import Net.coobird.thumbnailator.geometry.positions;public class Test {public static void main (string[] args) throws IOException {Test thumbnailatortest = new Test ();//thumbnailatortest.test1 ();//thumbnailatortest.test2 ();// Thumbnailatortest.test3 ();//thumbnailatortest.test4 ();//thumbnailatortest.test5 ();//thumbnailatortest.test6 (); Thumbnailatortest.test7 ();//thumbnailatortest.test8 ();//thumbnailatortest.test9 ();} /** * Specify size to scale * * @throws ioexception */private void Test1 () throws IOException {/* * size (width,height) If picture shape factor 200 small, high ratio 300 Small, unchanged * if the picture shape factor 200 small, high than 300, the height shrinks to 300, the picture proportion is unchanged if the picture shape Factor 200 big, the height is smaller than 300, the horizontal shrinks to 200, the picture proportion does not change * if the picture shape factor 200 is large, the picture proportionally shrinks, the height is 300 or the height is 200 * Thumbnails.of ("e:\\ picture \\15.jpg"). Size ($). ToFile ("e:\\ picture \\image_200x300.jpg"); Thumbnails.of ("e:\\ picture \\15.jpg"). Size (2560, 2048). tOfile ("e:\\ picture \\image_2560x2048.jpg");} /** * Scales proportionally * * @throws ioexception */private void Test2 () throws IOException {/** * scale (proportional) */thumbnails.of ("e:\\ picture \\15.jpg "). Scale (0.25f). ToFile (" e:\\ picture \\image_25%.jpg "); Thumbnails.of ("e:\\ picture \\15.jpg"). Scale (1.10f). ToFile ("e:\\ picture \\image_110%.jpg");} /** * Do not scale, specify size to zoom * * @throws ioexception */private void Test3 () throws IOException {/** * Keepaspectratio (FALSE) by default Proportionally scaled */thumbnails.of ("e:\\ picture \\15.jpg"). Size (+). Keepaspectratio (False). ToFile ("e:\\ picture \\image_120x120.jpg ");} /** * Rotation * * @throws ioexception */private void Test4 () throws IOException {/** * rotate (angle), positive: Clockwise negative: Counterclockwise */THUMBNAILS.O F ("e:\\ picture \\15.jpg"). Size (for all, 1024x768). ToFile ("e:\\ picture \\image+90.jpg") rotate. Thumbnails.of ("e:\\ picture \\15.jpg"). Size (for all, 1024x768). Rotate ( -90). ToFile ("e:\\ picture \\iamge-90.jpg");} /** * Watermark * * @throws ioexception */private void Test5 () throws IOException {/** * watermark (position, watermark, transparency) */thumbnails.of (" e:\\ picture \\images/15.jpg "). Size (for all, 1024x768). Watermark (Positions.bottom_right,imageio.read (New File ("e:\\ picture \\watermark.png")), 0.5f). Outputquality (0.8f). ToFile ("e:\\ picture \\image_watermark_bottom_right.jpg "); Thumbnails.of ("e:\\ picture \\15.jpg"). Size (for all, 1024x768). Watermark (Positions.center,imageio.read ("e:\\ picture \ \ Watermark.png ")), 0.5f). Outputquality (0.8f). ToFile (" e:\\ picture \\image_watermark_center.jpg ");} /** * cropping * * @throws ioexception */private void Test6 () throws IOException {/** * Picture Center 400*400 area */thumbnails.of ("e:\\ pictures \ \15.jpg "). Sourceregion (Positions.center, 400,400). Size ($, $). Keepaspectratio (False). ToFile (" e:\\ picture \\image_ Region_center.jpg ")/** * picture right bottom 400*400 area */thumbnails.of (" e:\\ picture \\15.jpg "). Sourceregion (Positions.bottom_right, (+). Size ($). Keepaspectratio (False). ToFile ("e:\\ picture \\image_region_bootom_right.jpg");/** * Specify coordinates */ Thumbnails.of ("e:\\ picture \\15.jpg"). The Sourceregion (at (+), (+). Size ($). Keepaspectratio (False). ToFile ("E:\ \ picture \\image_region_coord.jpg ");} /** * Conversion Image Format * * @throws ioexception */private void test7 () throws IOException {/** * OutputFormat (image format) */thumbnails.of ("e:\\ picture \\15.jpg"). Size (in a few, 1024x768). OutputFormat ("png "). ToFile (" e:\\ picture \\image_1280x1024.png "); Thumbnails.of ("e:\\ picture \\15.jpg"). Size (for all, 1024x768). OutputFormat ("GIF"). ToFile ("e:\\ picture \\image_1280x1024.gif");} /** * Output to OutputStream * * @throws ioexception */private void Test8 () throws IOException {/** * Tooutputstream (Stream object) */OUTP Utstream OS = new FileOutputStream ("e:\\ picture \\image_1280x1024_OutputStream.png"); Thumbnails.of ("e:\\ picture \\15.jpg"). Size (for all, 1024x768). Tooutputstream (OS); /** * Output to BufferedImage * * @throws ioexception */private void Test9 () throws IOException {/** * asbufferedimage () return Buffe Redimage */bufferedimage thumbnail = thumbnails.of ("e:\\ picture \\15.jpg"). Size (1280,1024). Asbufferedimage (); I Mageio.write (thumbnail, "jpg", New File ("e:\\ picture \\image_1280x1024_BufferedImage.jpg"));}}
Jar Package Required: Thumbnailator-0.4.2-all.jar
Java Picture Processing