Public Boolean Createthumbnail (String _Todir, String _FromDir) throws exception {// store String Todir = _todir; string proDir = _fromdir;
double Ratio = 0.0; File ThF = new File (todir); InputStream input = new FileInputStream (fromdir); BufferedImage Bi = ImageIO.read (input); // getInputStream () // assuming maximum image width and height 80 80 Image Itemp = Bi.getscaledInstance (80, 80, bi.scale_smooth); if ((bi.getHeight ()> 80) || (bi.getWidth ()> 80)) {if (bi.getHeight ()> bi.getwidth )) Ratio = 80.0 / bi.getHeight (); else ratio = 80.0 / bi.getwidth ();}
AffineTransformop op = New AffineTransformop (AffineTransform.getscaleInstance (Ratio, Ratio), NULL); itemp = op.filter (BI, NULL); graphics grd = itemp.getgraphics ();
// Fill your marker word grd.setcolor (color.red); Grd.SetFont (New Font ("Times New Roman", Font.Plain, 18)); Grd.DrawString ("YangTom", 30, 10) Grd.dispose ();
Try {imageio.write ((BufferedImage) Itemp, getExt (TODIR), THF);} catch (exception ex) {throw new exception ("imageio.write error in creathum .:" ex. maxMessage ()); {IF (Input! = Null) {Try {INPUT.CLOSE ();} catch (exception e) {system.out.println ("Close The InputStream IS Fail:"); E.PrintStackTrace ();}}} return (TRUE);
// Get suffix private string getExt (string dir) {
String filename = DIR; int lastdot = filename.lastindexof ("."); String ext = filename.substring (Lastdot 1);
Return Ext;