This article describes the Java implementation of the site to upload pictures stamped method. Share to everyone for your reference. Specifically as follows:
Recently bored, on a will alumni, feel alumni picture will join a chapter, hehe, oneself also did a, but only suitable jpg format. Sent out to give you research and research. Welcome to the discussion!
It's old code.
/************************************************ * <p>java The operation of the picture (only use JPG) </p> * The signature of the picture <br> * Thumbnails of pictures <br> * <p>title:java action on pictures (only jpg) </p> * <p>CreateData:2004-12-2</p> * <p >Description:</p> * <p>copyright:copyright (c) 2004</p> * @author Wang * @version 1.0 ****************
/package com.cn.wangk.test;
Import java.io.*;
Import Com.sun.image.codec.jpeg.*;//sun company only provides JPG picture file Coding API import Java.awt.Font;
Import Java.awt.Graphics;
Import Java.awt.Image;
Import Java.awt.geom.AffineTransform;
Import java.awt.image.AffineTransformOp;
Import Java.awt.image.BufferedImage;
Import Java.awt.image.ImageObserver;
Import Javax.imageio.ImageIO;
o = new File ("c:\\4.jpg"); Read picture file String ImagePath = "C:\\Documents and Settings\\administrator" + "\\My documentS\\my pictures\\1.jpg ";
Stamped picture file String toimagepth = "C:\\1.jpg";
Get the picture of the file stream InputStream ImageIn;
ImageIn = new FileInputStream (new File (ImagePath));
Gets the input encoder, encodes the file stream in jpg format Jpegimagedecoder decoder = Jpegcodec.createjpegdecoder (ImageIn);
Get the encoded image object BufferedImage image = Decoder.decodeasbufferedimage ();
Graphics g = image.getgraphics ();
try {InputStream imageIn2 = null;
IMAGEIN2 = new FileInputStream (new File (toimagepth));
Gets the input encoder, encodes the file stream in jpg format jpegimagedecoder decoder2 = Jpegcodec. Createjpegdecoder (IMAGEIN2);
Get the encoded image object BufferedImage Image2 = Decoder2.decodeasbufferedimage ();
Stamped picture Chapter ImageObserver obser = null;
int x = Image.getwidth ()-image2.getwidth ();
int y = image.getheight ()-image2.getheight ();
G.drawimage (Image2, x, Y, obser); catch (FileNotFoundException e) {//Open file failed to show chapter picture does not exist, this time directly stampedDocument chapter (signature) G.setfont (New Font ("Song Body", Font.plain, 18);
g.DrawString ("Autumn Studio", Image.getwidth ()-Image.getheight ()-20);
g.DrawString ("water_wang@xs.zj.cn", Image.getwidth ()-180, Image.getheight ()-10);
} g.dispose ();
Imageio.write (image, "jpeg", FO);
System.out.println ("OK");
catch (FileNotFoundException e) {//automatically generate catch block E.printstacktrace ();
catch (Imageformatexception e) {//automatically generate catch block E.printstacktrace ();
catch (IOException e) {//automatically generate catch block E.printstacktrace (); } public static void Savefixedboundicon (File imagefile, int height, int width) throws Exception {double R
Atio = 0.0;
if (ImageFile = null | |!imagefile.isfile ()) throw new Exception (ImageFile + "Cannot find the specified file!");
String FilePath = Imagefile.getpath ();
BufferedImage Bi = Imageio.read (ImageFile); if (Bi.getheight () > height) | | (Bi.getwidth () > width)) {if (Bi.getheight () > Bi.getwidth ()) {Ratio = (new Integer (height)). Doublevalue ()/Bi.getheig
HT ();
else {Ratio = (new Integer (width)). Doublevalue ()/bi.getwidth ();
File SaveFile = new file (FilePath + "_" + Height + "_" + width + ". jpg");
Image itemp = bi.getscaledinstance (width, height, image.scale_smooth);
Affinetransformop op = new Affinetransformop (affinetransform. Getscaleinstance (Ratio, Ratio), NULL);
itemp = Op.filter (Bi, NULL);
try {imageio.write (bufferedimage) itemp, "JPEG", savefile);
' Catch (Exception ex) {}} ' public static void main (string[] args) {//Test ts = new Test ();
try {Test.savefixedboundicon (new File ("C:\\test.jpg"), 200, 200);
catch (Exception e) {//automatically generate catch block E.printstacktrace ();
} } }
I hope this article will help you with your Java programming.