Java Image processing Open source framework

Source: Internet
Author: User

Java Image processing Open source framework

Never understood, Java open source framework what meaning, collect data to draw the following conclusions

In fact, the Java framework can be understood as a tool or a plug-in, a common, common technology package, to deal with some of the basic, cumbersome problems.

Thumbnailator is an excellent image processing Google Open source Java class Library. The processing effect is much better than the Java API. The process is simplified from the classes in which the API provides existing image files and image objects, and two or three lines of code can generate processed pictures from existing images and allow fine-tuning of how the images are generated while maintaining the minimum amount of code that needs to be written. It also supports batch processing of all pictures in one directory.

Supported processing operations: Image zoom, area clipping, watermark, rotate, maintain proportions.

Also worth mentioning is, Thumbnailator still constantly updated, how, feel very secure it!

Thumbnailator Official website: http://code.google.com/p/thumbnailator/

Below we describe how to use the Thumbnailator

Original:

1. Scale with the specified size

[Java]View PlainCopy
  1. Size (width, height)
  2. /*
  3. * If the picture shape factor 200 small, high than 300 small, unchanged
  4. * If the picture shape factor 200 small, high ratio 300, high shrink to 300, picture proportion unchanged
  5. * If the picture shape factor 200, the height is 300 small, the cross shrinks to 200, the picture proportion does not change
  6. * If the picture shape factor 200 large, high than 300, the picture is scaled down, the horizontal is 200 or 300
  7. */
  8. Thumbnails.of ("images/a380_1280x1024.jpg")
  9. . Size (max. )
  10. . ToFile ("c:/a380_200x300.jpg");
  11. Thumbnails.of ("images/a380_1280x1024.jpg")
  12. . Size (2560, 2048)
  13. . ToFile ("c:/a380_2560x2048.jpg");

2. Scale by scale

[Java]View PlainCopy
    1. Scale (proportional)
    2. Thumbnails.of ("images/a380_1280x1024.jpg")
    3. . Scale (0.25f)
    4. . ToFile ("c:/a380_25%.jpg");
    5. Thumbnails.of ("images/a380_1280x1024.jpg")
    6. . Scale (1.10f)
    7. . ToFile ("c:/a380_110%.jpg");

3, do not scale, specify size to zoom

[Java]View PlainCopy
    1. Keepaspectratio (false) is scaled by default
    2. Thumbnails.of ("images/a380_1280x1024.jpg")
    3. . Size ($, $)
    4. . Keepaspectratio (false)
    5. . ToFile ("c:/a380_200x200.jpg");

4. Rotation

[Java]View PlainCopy
  1. Rotate (angle), positive: clockwise negative: counterclockwise
  2. Thumbnails.of ("images/a380_1280x1024.jpg")
  3. . Size (for all,1024x768)
  4. . Rotate (+)
  5. . ToFile ("c:/a380_rotate+90.jpg");
  6. Thumbnails.of ("images/a380_1280x1024.jpg")
  7. . Size (for all,1024x768)
  8. . Rotate (-)
  9. . ToFile ("c:/a380_rotate-90.jpg");

5. Watermark

[Java]View PlainCopy
  1. Watermark (location, watermark, transparency)
  2. Thumbnails.of ("images/a380_1280x1024.jpg")
  3. . Size (for all,1024x768)
  4. . Watermark (Positions.bottom_right,imageio.read (NewFile ("Images/watermark.png")),0.5f)
  5. . outputquality (0.8f)
  6. . ToFile ("c:/a380_watermark_bottom_right.jpg");
  7. Thumbnails.of ("images/a380_1280x1024.jpg")
  8. . Size (for all,1024x768)
  9. . Watermark (Positions.center,imageio.read (NewFile ("Images/watermark.png")),0.5f)
  10. . outputquality (0.8f)
  11. . ToFile ("c:/a380_watermark_center.jpg");

6, cutting

[Java]View PlainCopy
  1. Sourceregion ()
  2. Image Center 400*400 Area
  3. Thumbnails.of ("images/a380_1280x1024.jpg")
  4. . sourceregion (Positions.center, I, I)
  5. . Size ($, $)
  6. . Keepaspectratio (false)
  7. . ToFile ("c:/a380_region_center.jpg");
  8. Picture lower right 400*400 area
  9. Thumbnails.of ("images/a380_1280x1024.jpg")
  10. . sourceregion (Positions.bottom_right, I, I)
  11. . Size ($, $)
  12. . Keepaspectratio (false)
  13. . ToFile ("c:/a380_region_bootom_right.jpg");
  14. Specify coordinates
  15. Thumbnails.of ("images/a380_1280x1024.jpg")
  16. . sourceregion (+----)
  17. . Size ($, $)
  18. . Keepaspectratio (false)
  19. . ToFile ("c:/a380_region_coord.jpg");

7. Conversion image format

[Java]View PlainCopy
  1. OutputFormat (image format)
  2. Thumbnails.of ("images/a380_1280x1024.jpg")
  3. . Size (for all,1024x768)
  4. . OutputFormat ("PNG")
  5. . ToFile ("c:/a380_1280x1024.png");
  6. Thumbnails.of ("images/a380_1280x1024.jpg")
  7. . Size (for all,1024x768)
  8. . OutputFormat ("gif")
  9. . ToFile ("c:/a380_1280x1024.gif");

8, output to OutputStream

[Java]View PlainCopy
    1. Tooutputstream (Stream object)
    2. Outputstreamos=newfileoutputstream ("c:/a380_1280x1024_outputstream.png");
    3. Thumbnails.of ("images/a380_1280x1024.jpg")
    4. . Size (for all,1024x768)
    5. . Tooutputstream (OS);

9, output to BufferedImage

[Java]View PlainCopy
      1. Asbufferedimage () return bufferedimage
      2. Bufferedimagethumbnail=thumbnails.of ("images/a380_1280x1024.jpg")
      3. . Size (for all,1024x768)
      4. . Asbufferedimage ();
      5. Imageio.write (thumbnail,"jpg", NewFile ("c:/a380_1280x1024_bufferedimage.jpg"));

Reproduced above reprint copy csdn The Great God writes the open Source tool.

Java Image processing Open source framework

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.