JSP plus picture water printing

xiaoxiao2021-04-06  280

This is a picture watermark! Package com.pic;

Import java.awt. *; import java.awt.event. *; import java.io. *; import java.awt.image. *; import org.w3c.dom. *; import com.sun.image.codec. JPEG. *; import javax.imageio. *;

Public class imgbean_i {public void imgbean_i () {

}

public void ImgYin (String Imagename_biao, String ImgName) {try {File _file = new File (ImgName); Image src = ImageIO.read (_file); int wideth = src.getWidth (null); int height = src.getHeight (null BufferedImage Image = New BufferedImage (Wideth, Height, BufferedImage.Type_INT_RGB); Graphics G = Image.createGraphics (); g.drawImage (SRC, 0, 0, Wideth, Height, NULL);

// watermark file File _filebiao = new File (Imagename_biao); Image src_biao = ImageIO.read (_filebiao); int wideth_biao = src_biao.getWidth (null); int height_biao = src_biao.getHeight (null); g.drawImage (src_biao, wideth -110, height-30, wideth_biao, height_biao, null); /// g.dispose (); FileOutputStream out = new FileOutputStream (imgName); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder (out); encoder.encode (image); out .close ();} catch (exception e) {system.out.println (e);}}}

/ This is a package com.pic plus a text watermark;

Import java.awt. *; import java.awt.event. *; import java.io. *; import java.awt.image. *; import org.w3c.dom. *; import com.sun.image.codec. JPEG. *; import javax.imageio. *;

public class ImgBean {public void ImgBean () {} public void ImgYin (String s, String ImgName) {try {File _file = new File (ImgName); Image src = ImageIO.read (_file); int wideth = src.getWidth ( null); int height = src.getHeight (null); BufferedImage image = new BufferedImage (wideth, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.createGraphics (); g.drawImage (src, 0,0, wideth, height , NULL); // string s = "www.qhd.com.cn"; g.setColor (Color.red); G.SetFont (New Font ("Song", Font.Plain, 20); font aa = New Font ("Song", Font.Plain, 20);

g.drawString (s, wideth-150, height-10); g.dispose (); FileOutputStream out = new FileOutputStream (ImgName); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder (out); encoder.encode (image); out.close ();} Catch (Exception E) {system.out.println (e);}}} JPG picture water printing <% @ Page Autoflush = "false" contenttype = "text / html; charSet = GB2312" import = "Java.io.fileinputStream, java.io.fileoutputstream, java.awt. *, java.awt.mage. *, com.sun.mage.codec.jpeg. *, java.util. *"%> <% OUT .clear (); Response.addheader ("Pragma", "No-cache"); Response.addheader ("cache-control", "no-cache"); response.adddateheader ("expries", 0); string filename = source image path; String outFileName = generate new image path; FileInputStream sFile = new FileInputStream (FileName); // create a FileInputStream object to obtain data stream Image src = javax.imageio.ImageIO.read (sFile) from the source picture; / / Create an Image object and fill int width = src.getwidth (null) in source image data; // Get source map wide int Height = src.getHeight (null); // Get the source map length IF (Width> 70 && height> 30) {BufferedImage Image = New BufferedImage (Width, Height, BufferedImage.Type_INT _RGB); // Create a bufferedImage to use the image operation container graphics g = image.getgraphchics (); // Create a drawing environment to draw image G.drawImage (src, 0, 0, 10, heliGHT, null); // Put the original image data into this BufferedImage G.SetFont (New Font ("Times New Roman", Font.Plain, 12)); // Setting text Font String Rand = "NetBuilder"; G.SetColor (Color .black); // Set text color g.drawstring (Rand, Width-55, height); // Write the text character g.dispose () to BUFFEREDIMAGE (); // Make changes to change into inputputstream outi = new fileoutputstream (OutfileName) ; // Create Output Files JPEGIMAGEENCODER Encodera = JPEGCODEC.CREATEJPEGENCODER (OUTI); // Create JPEG Code Object Encodera.Encode (Image);

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

New Post(0)