Upload pictures to play watermark

xiaoxiao2021-03-06  42

It is used in JSPSMART.UPLOAD, this is the IMGBean code

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-110, 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);}}} ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ // Watermark .javaimport java.io.file; import java.io.fileoutputstream; Import Javax.imageIo.imageio;

Import java.awt.graphics; import java.awt.image; import java.awt.image.bufferedImage

Import com.sun.image.codec.jpeg.jpegcodec; import com.sun.image.codec.jpeg.jpegimageEncoder;

public class WaterMark {public void imgMark (String strOriginalFileName, String strWaterMarkFileName) {try {// the source file File fileOriginal = new File (strOriginalFileName); Image imageOriginal = ImageIO.read (fileOriginal); int widthOriginal = imageOriginal.getWidth (null); int heightOriginal = imageOriginal.getHeight (null); System.out.println ( "widthOriginal:" widthOriginal "/ theightOriginal:" heightOriginal); BufferedImage bufImage = new BufferedImage (widthOriginal, heightOriginal, BufferedImage.TYPE_INT_RGB); Graphics g = BUFIMAGE.CREATEGRAPHICs (); g.drawImage (imageoriginal, 0,0, widthoriginal, heightoriginal, null);

// watermark file File fileWaterMark = new File (strWaterMarkFileName); Image imageWaterMark = ImageIO.read (fileWaterMark); int widthWaterMark = imageWaterMark.getWidth (null); int heightWaterMark = imageWaterMark.getHeight (null); System.out.println ( " Widthwatermark: " widthwatermark " / theightwatermark: " heightwatermark);

// Watermarking files in the lower right corner of the source file G. DrawImage (ImageWatermark, Widtoriginal - Widthwatermark, Heightoriginal - Heightwatermark, Widthwatermark, Heightwatermark, null; g.dispose ();

FileOutputStream fos = new FileOutputStream (strOriginalFileName); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder (fos); encoder.encode (bufImage); fos.flush (); fos.close (); fos = null;} catch (Exception e) {e .printstacktrace ();}}

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

New Post(0)