JSP upload images and generate a zoom chart or watermark

xiaoxiao2021-04-06  334

// add watermark, filePath source image path, watermark watermark image path public static boolean createMark (String filePath, String watermark) {ImageIcon imgIcon = new ImageIcon (filePath); Image theImg = imgIcon.getImage (); ImageIcon waterIcon = new ImageIcon ( watermark); Image waterImg = waterIcon.getImage (); int width = theImg.getWidth (null); int height = theImg.getHeight (null); BufferedImage bimage = new BufferedImage (width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = BIMAGE.CREATGRAPHICs (); g.setColor (Color.red); g.setBackground (color.white); g.drawImage (THEIMG, 0, 0, NULL); G.DrawImage (WaterImg, 100, 100, null); g.drawString ( "12233", 10,10); // add text g.dispose (); try {FileOutputStream out = new FileOutputStream (filePath); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder (out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam (BIMAGE); param.setquality (50f, true); encoder.encode (bimage, param); out.close ();} catch (Exception E) {Return False;} return true;}

转载请注明原文地址:https://www.9cbs.com/read-132293.html

New Post(0)