code=Java]
package exif2;import java.io.*;
import java.util.Date;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.AffineTransform;
import javax.imageio.*;
import javax.imageio.stream.ImageInputStream;import mediautil.gen.directio.*;
import mediautil.gen.Log;
import mediautil.image.ImageResources;
import mediautil.image.jpeg.LLJTran;
import mediautil.image.jpeg.AbstractImageInfo;
import mediautil.image.jpeg.Exif;
import mediautil.image.jpeg.Entry;
import mediautil.image.jpeg.LLJTranException;public class SetGpsInfo {    private static byte[] getThumbnailImage(InputStream ip) throws IOException  請問ip是做什麼用的還有這一小段再做什麼
    {
        ImageReader reader;
        ImageInputStream iis = ImageIO.createImageInputStream(ip);
        reader = (ImageReader) ImageIO.getImageReaders(iis).next();
        reader.setInput(iis);
        BufferedImage image = reader.read(0);
        iis.close();
        int t, longer, shorter;
        longer = image.getWidth();
        shorter = image.getHeight();
        if(shorter > longer)
        {
            t = longer;
            longer = shorter;
            shorter = t;
        }
        double factor = 160/(double)longer;
        double factor1 = 120/(double)shorter;
        if(factor1 > factor)
            factor = factor1;
        AffineTransform tx = new AffineTransform();
        tx.scale(factor, factor);
        AffineTransformOp affineOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
        image = affineOp.filter(image, null);        ByteArrayOutputStream byteStream = new ByteArrayOutputStream(2048);
        String format = "JPG";
        ImageIO.write(image, format, byteStream);        return byteStream.toByteArray();
    }    public static void main(String[] args) throws Exception {
        if(args.length != 2)
        {
            System.out.println("Usage: java LLJTranTutorial <inputFile> <outputFile>");
            System.exit(1);
        }        // 1. Read the Image from inputFile upto READ_HEADER along with the
        //    ImageReader using SplitInputStream and Generate a Thumbnail from
        //    the Image.
        InputStream fip = new FileInputStream(args[0]); // No need to buffer <---還有這段我知道要引入一個新的檔案進來有辦法直接指定路徑嗎如果路徑是C://b.jpg 請問要怎麼修改  還是是在別的地方能提示我該怎麼做才能提取到要引入的 C://b.jpg 的圖片
        SplitInputStream sip = new SplitInputStream(fip);
        // Create a substream for LLJTran to use
        InputStream subIp = sip.createSubStream();
        LLJTran llj = new LLJTran(subIp);
        // Normally it would be better to read the entire image when reading
        // shared. But LLJTran only needs to read upto header for loading
        // imageInfo and using xferInfo.
        llj.initRead(LLJTran.READ_HEADER, true, true);
        sip.attachSubReader(llj, subIp);
        // LLJTran reads the image when the below API reads from sip via
        // nextRead() calls made by sip.
        byte newThumbnail[] = getThumbnailImage(sip);
        sip.wrapup();
        fip.close();        // Check llj for errors
        String msg = llj.getErrorMsg();
        if(msg != null)
        {
            System.out.println("Error in LLJTran While Loading Image: " + msg);
            Exception e = llj.getException();
            if(e != null)
            {
                System.out.println("Got an Exception, throwing it..");
                throw e;
            }
            System.exit(1);
        }        // 2. If the image has a Thumbnail (Which means it has a Exif Header)
        //    print a message and exit.
        AbstractImageInfo imageInfo = llj.getImageInfo();
        if(imageInfo.getThumbnailLength() > 0)
        {
            System.out.println("Image already has a Thumbnail. Exitting..");
            System.exit(1);
        }        // 3. If the Image does not have an Exif Header create a dummy Exif
        //    Header
        if(!(imageInfo instanceof Exif))
        {
            System.out.println("Adding a Dummy Exif Header");
            llj.addAppx(LLJTran.dummyExifHeader, 0,
                        LLJTran.dummyExifHeader.length, true);
            imageInfo = llj.getImageInfo(); // This would have changed            Exif exif = (Exif) imageInfo;            // Changed Date/Time and dimensions in Dummy Exif
            Entry entry = exif.getTagValue(Exif.DATETIME, true);
            if(entry != null)
                entry.setValue(0, "1998:08:18 11:15:00");
            entry = exif.getTagValue(Exif.DATETIMEORIGINAL, true);
            if(entry != null)
                entry.setValue(0, "1998:08:18 11:15:00");
            entry = exif.getTagValue(Exif.DATETIMEDIGITIZED, true);
            if(entry != null)
                entry.setValue(0, "1998:08:18 11:15:00");            int imageWidth = llj.getWidth();
            int imageHeight = llj.getHeight();
            if(imageWidth > 0 && imageHeight > 0)
            {
                entry = exif.getTagValue(Exif.EXIFIMAGEWIDTH, true);
                if(entry != null)
                    entry.setValue(0, new Integer(imageWidth));
                entry = exif.getTagValue(Exif.EXIFIMAGELENGTH, true);
                if(entry != null)
                    entry.setValue(0, new Integer(imageHeight));
            }
        }        // 4. Set the new Thumbnail
        if(llj.setThumbnail(newThumbnail, 0, newThumbnail.length,
                             ImageResources.EXT_JPG))
            System.out.println("Successfully Set New Thumbnail");
        else
            System.out.println("Error Setting New Thumbnail");        // 5. Transfer the image from inputFile to outputFile replacing the new
        //    Exif with the Thumbnail so that outputFile has a Thumbnail.
        fip = new BufferedInputStream(new FileInputStream(args[0]));
        OutputStream out = new BufferedOutputStream(
                                new FileOutputStream(args[1]));
        // Replace the new Exif Header in llj while copying the image from fip
        // to out
        llj.xferInfo(fip, out, LLJTran.REPLACE, LLJTran.RETAIN);
        fip.close();
        out.close();        // Cleanup
        llj.freeMemory();
    }
}[
[/code]