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
- Size (width, height)
- /*
- * If the picture shape factor 200 small, high than 300 small, unchanged
- * If the picture shape factor 200 small, high ratio 300, high shrink to 300, picture proportion unchanged
- * If the picture shape factor 200, the height is 300 small, the cross shrinks to 200, the picture proportion does not change
- * If the picture shape factor 200 large, high than 300, the picture is scaled down, the horizontal is 200 or 300
- */
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Size (max. )
- . ToFile ("c:/a380_200x300.jpg");
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Size (2560, 2048)
- . ToFile ("c:/a380_2560x2048.jpg");
2. Scale by scale
[Java]View PlainCopy
- Scale (proportional)
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Scale (0.25f)
- . ToFile ("c:/a380_25%.jpg");
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Scale (1.10f)
- . ToFile ("c:/a380_110%.jpg");
3, do not scale, specify size to zoom
[Java]View PlainCopy
- Keepaspectratio (false) is scaled by default
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Size ($, $)
- . Keepaspectratio (false)
- . ToFile ("c:/a380_200x200.jpg");
4. Rotation
[Java]View PlainCopy
- Rotate (angle), positive: clockwise negative: counterclockwise
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Size (for all,1024x768)
- . Rotate (+)
- . ToFile ("c:/a380_rotate+90.jpg");
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Size (for all,1024x768)
- . Rotate (-)
- . ToFile ("c:/a380_rotate-90.jpg");
5. Watermark
[Java]View PlainCopy
- Watermark (location, watermark, transparency)
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Size (for all,1024x768)
- . Watermark (Positions.bottom_right,imageio.read (NewFile ("Images/watermark.png")),0.5f)
- . outputquality (0.8f)
- . ToFile ("c:/a380_watermark_bottom_right.jpg");
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Size (for all,1024x768)
- . Watermark (Positions.center,imageio.read (NewFile ("Images/watermark.png")),0.5f)
- . outputquality (0.8f)
- . ToFile ("c:/a380_watermark_center.jpg");
6, cutting
[Java]View PlainCopy
- Sourceregion ()
- Image Center 400*400 Area
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . sourceregion (Positions.center, I, I)
- . Size ($, $)
- . Keepaspectratio (false)
- . ToFile ("c:/a380_region_center.jpg");
- Picture lower right 400*400 area
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . sourceregion (Positions.bottom_right, I, I)
- . Size ($, $)
- . Keepaspectratio (false)
- . ToFile ("c:/a380_region_bootom_right.jpg");
- Specify coordinates
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . sourceregion (+----)
- . Size ($, $)
- . Keepaspectratio (false)
- . ToFile ("c:/a380_region_coord.jpg");
7. Conversion image format
[Java]View PlainCopy
- OutputFormat (image format)
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Size (for all,1024x768)
- . OutputFormat ("PNG")
- . ToFile ("c:/a380_1280x1024.png");
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Size (for all,1024x768)
- . OutputFormat ("gif")
- . ToFile ("c:/a380_1280x1024.gif");
8, output to OutputStream
[Java]View PlainCopy
- Tooutputstream (Stream object)
- Outputstreamos=newfileoutputstream ("c:/a380_1280x1024_outputstream.png");
- Thumbnails.of ("images/a380_1280x1024.jpg")
- . Size (for all,1024x768)
- . Tooutputstream (OS);
9, output to BufferedImage
[Java]View PlainCopy
- Asbufferedimage () return bufferedimage
- Bufferedimagethumbnail=thumbnails.of ("images/a380_1280x1024.jpg")
- . Size (for all,1024x768)
- . Asbufferedimage ();
- 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