You are viewing a plain text version of this content. The canonical link for it is here.
Posted to sanselan-commits@incubator.apache.org by cm...@apache.org on 2008/08/04 20:44:52 UTC

svn commit: r682502 - in /incubator/sanselan/trunk/src: examples/ examples/java/ examples/java/org/ examples/java/org/apache/ examples/java/org/apache/sanselan/ examples/java/org/apache/sanselan/sampleUsage/ main/java/org/apache/sanselan/sampleUsage/

Author: cmchen
Date: Mon Aug  4 13:44:51 2008
New Revision: 682502

URL: http://svn.apache.org/viewvc?rev=682502&view=rev
Log:
* Moved the example/sample code to a new top-level source folder, "example."

Added:
    incubator/sanselan/trunk/src/examples/
    incubator/sanselan/trunk/src/examples/java/
    incubator/sanselan/trunk/src/examples/java/org/
    incubator/sanselan/trunk/src/examples/java/org/apache/
    incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/
    incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/
    incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageReadExample.java   (with props)
    incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java   (with props)
    incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/MetadataExample.java   (with props)
    incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/SampleUsage.java   (with props)
    incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java   (with props)
Removed:
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/sampleUsage/ImageReadExample.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/sampleUsage/MetadataExample.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/sampleUsage/SampleUsage.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java

Added: incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageReadExample.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageReadExample.java?rev=682502&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageReadExample.java (added)
+++ incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageReadExample.java Mon Aug  4 13:44:51 2008
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sanselan.sampleUsage;
+
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Transparency;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.SanselanConstants;
+import org.apache.sanselan.common.IBufferedImageFactory;
+
+public class ImageReadExample
+{
+	public static BufferedImage imageReadExample(File file)
+			throws ImageReadException, IOException
+	{
+		Map params = new HashMap();
+
+		// set optional parameters if you like
+		params.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
+				new ManagedImageBufferedImageFactory());
+
+		//		params.put(SanselanConstants.PARAM_KEY_VERBOSE, Boolean.TRUE);
+
+		// read image
+		BufferedImage image = Sanselan.getBufferedImage(file, params);
+
+		return image;
+	}
+
+	public static class ManagedImageBufferedImageFactory
+			implements
+				IBufferedImageFactory
+	{
+
+		public BufferedImage getColorBufferedImage(int width, int height,
+				boolean hasAlpha)
+		{
+			GraphicsEnvironment ge = GraphicsEnvironment
+					.getLocalGraphicsEnvironment();
+			GraphicsDevice gd = ge.getDefaultScreenDevice();
+			GraphicsConfiguration gc = gd.getDefaultConfiguration();
+			return gc.createCompatibleImage(width, height,
+					Transparency.TRANSLUCENT);
+		}
+
+		public BufferedImage getGrayscaleBufferedImage(int width, int height,
+				boolean hasAlpha)
+		{
+			return getColorBufferedImage(width, height, hasAlpha);
+		}
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageReadExample.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java?rev=682502&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java (added)
+++ incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java Mon Aug  4 13:44:51 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sanselan.sampleUsage;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sanselan.ImageFormat;
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.SanselanConstants;
+import org.apache.sanselan.formats.tiff.constants.TiffConstants;
+
+public class ImageWriteExample
+{
+	public static byte[] imageWriteExample(File file)
+			throws ImageReadException, ImageWriteException, IOException
+	{
+		// read image
+		BufferedImage image = Sanselan.getBufferedImage(file);
+
+		ImageFormat format = ImageFormat.IMAGE_FORMAT_TIFF;
+		Map params = new HashMap();
+
+		// set optional parameters if you like
+		params.put(SanselanConstants.PARAM_KEY_COMPRESSION, new Integer(
+				TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED));
+
+		byte bytes[] = Sanselan.writeImageToBytes(image, format, params);
+
+		return bytes;
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/MetadataExample.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/MetadataExample.java?rev=682502&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/MetadataExample.java (added)
+++ incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/MetadataExample.java Mon Aug  4 13:44:51 2008
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sanselan.sampleUsage;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.common.IImageMetadata;
+import org.apache.sanselan.common.RationalNumber;
+import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
+import org.apache.sanselan.formats.tiff.TiffField;
+import org.apache.sanselan.formats.tiff.TiffImageMetadata;
+import org.apache.sanselan.formats.tiff.constants.TagInfo;
+import org.apache.sanselan.formats.tiff.constants.TiffConstants;
+
+public class MetadataExample
+{
+	public static void metadataExample(File file) throws ImageReadException,
+			IOException
+	{
+		//        get all metadata stored in EXIF format (ie. from JPEG or TIFF).
+		//            org.w3c.dom.Node node = Sanselan.getMetadataObsolete(imageBytes);
+		IImageMetadata metadata = Sanselan.getMetadata(file);
+
+		//System.out.println(metadata);
+
+		if (metadata instanceof JpegImageMetadata)
+		{
+			JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+
+			// Jpeg EXIF metadata is stored in a TIFF-based directory structure
+			// and is identified with TIFF tags.
+			// Here we look for the "x resolution" tag, but
+			// we could just as easily search for any other tag.
+			//
+			// see the TiffConstants file for a list of TIFF tags.
+
+			System.out.println("file: " + file.getPath());
+
+			// print out various interesting EXIF tags.
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_XRESOLUTION);
+			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DATE_TIME);
+			printTagValue(jpegMetadata,
+					TiffConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
+			printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_CREATE_DATE);
+			printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_ISO);
+			printTagValue(jpegMetadata,
+					TiffConstants.EXIF_TAG_SHUTTER_SPEED_VALUE);
+			printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_APERTURE_VALUE);
+			printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_BRIGHTNESS_VALUE);
+			printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
+			printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LATITUDE);
+			printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
+			printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LONGITUDE);
+
+			System.out.println();
+
+			// simple interface to GPS data
+			TiffImageMetadata exifMetadata = jpegMetadata.getExif();
+			if (null != exifMetadata)
+			{
+				TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS();
+				if (null != gpsInfo)
+				{
+					String gpsDescription = gpsInfo.toString();
+					double longitude = gpsInfo.getLongitudeAsDegreesEast();
+					double latitude = gpsInfo.getLatitudeAsDegreesNorth();
+
+					System.out.println("	" + "GPS Description: " + gpsInfo);
+					System.out.println("	" + "GPS Longitude (Degrees East): " + longitude);
+					System.out.println("	" + "GPS Latitude (Degrees North): " + latitude);
+				}
+			}
+
+			// more specific example of how to manually access GPS values
+			TiffField gpsLatitudeRefField = jpegMetadata
+					.findEXIFValue(TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
+			TiffField gpsLatitudeField = jpegMetadata
+					.findEXIFValue(TiffConstants.GPS_TAG_GPS_LATITUDE);
+			TiffField gpsLongitudeRefField = jpegMetadata
+					.findEXIFValue(TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
+			TiffField gpsLongitudeField = jpegMetadata
+					.findEXIFValue(TiffConstants.GPS_TAG_GPS_LONGITUDE);
+			if (gpsLatitudeRefField != null && gpsLatitudeField != null
+					&& gpsLongitudeRefField != null
+					&& gpsLongitudeField != null)
+			{
+				// all of these values are strings.
+				String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue();
+				RationalNumber gpsLatitude[] = (RationalNumber[]) (gpsLatitudeField
+						.getValue());
+				String gpsLongitudeRef = (String) gpsLongitudeRefField
+						.getValue();
+				RationalNumber gpsLongitude[] = (RationalNumber[]) gpsLongitudeField
+						.getValue();
+
+				RationalNumber gpsLatitudeDegrees = gpsLatitude[0];
+				RationalNumber gpsLatitudeMinutes = gpsLatitude[1];
+				RationalNumber gpsLatitudeSeconds = gpsLatitude[2];
+
+				RationalNumber gpsLongitudeDegrees = gpsLongitude[0];
+				RationalNumber gpsLongitudeMinutes = gpsLongitude[1];
+				RationalNumber gpsLongitudeSeconds = gpsLongitude[2];
+
+				// This will format the gps info like so:
+				//
+				// gpsLatitude: 8 degrees, 40 minutes, 42.2 seconds S
+				// gpsLongitude: 115 degrees, 26 minutes, 21.8 seconds E
+
+				System.out.println("	" + "GPS Latitude: "
+						+ gpsLatitudeDegrees.toDisplayString() + " degrees, "
+						+ gpsLatitudeMinutes.toDisplayString() + " minutes, "
+						+ gpsLatitudeSeconds.toDisplayString() + " seconds "
+						+ gpsLatitudeRef);
+				System.out.println("	" + "GPS Longitude: "
+						+ gpsLongitudeDegrees.toDisplayString() + " degrees, "
+						+ gpsLongitudeMinutes.toDisplayString() + " minutes, "
+						+ gpsLongitudeSeconds.toDisplayString() + " seconds "
+						+ gpsLongitudeRef);
+
+			}
+
+			System.out.println();
+
+			ArrayList items = jpegMetadata.getItems();
+			for (int i = 0; i < items.size(); i++)
+			{
+				Object item = items.get(i);
+				System.out.println("	" + "item: " + item);
+			}
+
+			System.out.println();
+		}
+	}
+
+	private static void printTagValue(JpegImageMetadata jpegMetadata,
+			TagInfo tagInfo) throws ImageReadException, IOException
+	{
+		TiffField field = jpegMetadata.findEXIFValue(tagInfo);
+		if (field == null)
+			System.out.println(tagInfo.name + ": " + "Not Found.");
+		else
+			System.out.println(tagInfo.name + ": "
+					+ field.getValueDescription());
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/MetadataExample.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/SampleUsage.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/SampleUsage.java?rev=682502&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/SampleUsage.java (added)
+++ incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/SampleUsage.java Mon Aug  4 13:44:51 2008
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sanselan.sampleUsage;
+
+import java.awt.Dimension;
+import java.awt.color.ICC_Profile;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sanselan.FormatCompliance;
+import org.apache.sanselan.ImageFormat;
+import org.apache.sanselan.ImageInfo;
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.common.IImageMetadata;
+
+public class SampleUsage
+{
+
+	public SampleUsage()
+	{
+
+		try
+		{
+			// <b>Code won't work unless these variables are properly initialized. 
+			// 		Sanselan works equally well with File, byte array or InputStream inputs.</b>
+			BufferedImage someImage = null;
+			byte someBytes[] = null;
+			File someFile = null;
+			InputStream someInputStream = null;
+			OutputStream someOutputStream = null;
+
+			// <b>The Sanselan class provides a simple interface to the library. </b>
+
+			// <b>how to read an image: </b>
+			byte imageBytes[] = someBytes;
+			BufferedImage image_1 = Sanselan.getBufferedImage(imageBytes);
+
+			// <b>methods of Sanselan usually accept files, byte arrays, or inputstreams as arguments. </b>
+			BufferedImage image_2 = Sanselan.getBufferedImage(imageBytes);
+			File file = someFile;
+			BufferedImage image_3 = Sanselan.getBufferedImage(file);
+			InputStream is = someInputStream;
+			BufferedImage image_4 = Sanselan.getBufferedImage(is);
+
+			// <b>Write an image. </b>
+			BufferedImage image = someImage;
+			File dst = someFile;
+			ImageFormat format = ImageFormat.IMAGE_FORMAT_PNG;
+			Map optional_params = new HashMap();
+			Sanselan.writeImage(image, dst, format, optional_params);
+
+			OutputStream os = someOutputStream;
+			Sanselan.writeImage(image, os, format, optional_params);
+
+			// <b>get the image's embedded ICC Profile, if it has one. </b>
+			byte iccProfileBytes[] = Sanselan.getICCProfileBytes(imageBytes);
+
+			ICC_Profile iccProfile = Sanselan.getICCProfile(imageBytes);
+
+			// <b>get the image's width and height. </b>
+			Dimension d = Sanselan.getImageSize(imageBytes);
+
+			// <b>get all of the image's info (ie. bits per pixel, size, transparency, etc.) </b>
+			ImageInfo imageInfo = Sanselan.getImageInfo(imageBytes);
+
+			if (imageInfo.getColorType() == ImageInfo.COLOR_TYPE_GRAYSCALE)
+				System.out.println("Grayscale image.");
+			if (imageInfo.getHeight() > 1000)
+				System.out.println("Large image.");
+
+			// <b>try to guess the image's format. </b>
+			ImageFormat image_format = Sanselan.guessFormat(imageBytes);
+			image_format.equals(ImageFormat.IMAGE_FORMAT_PNG);
+
+			// <b>get all metadata stored in EXIF format (ie. from JPEG or TIFF). </b>
+			// <b>org.w3c.dom.Node node = Sanselan.getMetadataObsolete(imageBytes); </b>
+			IImageMetadata metdata = Sanselan.getMetadata(imageBytes);
+
+			// <b>print a dump of information about an image to stdout. </b>
+			Sanselan.dumpImageFile(imageBytes);
+
+			// <b>get a summary of format errors. </b>
+			FormatCompliance formatCompliance = Sanselan
+					.getFormatCompliance(imageBytes);
+
+		}
+		catch (Exception e)
+		{
+
+		}
+	}
+}

Propchange: incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/SampleUsage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java?rev=682502&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java (added)
+++ incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java Mon Aug  4 13:44:51 2008
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sanselan.sampleUsage;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.common.IImageMetadata;
+import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
+import org.apache.sanselan.formats.jpeg.exifRewrite.ExifRewriter;
+import org.apache.sanselan.formats.tiff.TiffImageMetadata;
+import org.apache.sanselan.formats.tiff.constants.TiffConstants;
+import org.apache.sanselan.formats.tiff.write.TiffOutputDirectory;
+import org.apache.sanselan.formats.tiff.write.TiffOutputField;
+import org.apache.sanselan.formats.tiff.write.TiffOutputSet;
+
+public class WriteExifMetadataExample
+{
+	public void removeExifMetadata(File jpegImageFile, File dst)
+			throws IOException, ImageReadException, ImageWriteException
+	{
+		OutputStream os = null;
+		try
+		{
+			os = new FileOutputStream(dst);
+			os = new BufferedOutputStream(os);
+
+			new ExifRewriter().removeExifMetadata(jpegImageFile, os);
+		}
+		finally
+		{
+			if (os != null)
+				try
+				{
+					os.close();
+				}
+				catch (IOException e)
+				{
+
+				}
+		}
+	}
+
+	public void changeExifMetadata(File jpegImageFile, File dst)
+			throws IOException, ImageReadException, ImageWriteException
+	{
+		OutputStream os = null;
+		try
+		{
+			TiffOutputSet outputSet =  null;
+
+			// note that metadata might be null if no metadata is found.
+			IImageMetadata metadata = Sanselan.getMetadata(jpegImageFile);
+			JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+			if (null != jpegMetadata)
+			{
+				// note that exif might be null if no Exif metadata is found.
+				TiffImageMetadata exif = jpegMetadata.getExif();
+
+				if (null != exif)
+				{
+					// TiffImageMetadata class is immutable (read-only).
+					// TiffOutputSet class represents the Exif data to write.
+					//
+					// Usually, we want to update existing Exif metadata by changing
+					// the values of a few fields, or adding a field.
+					// In these cases, it is easiest to use getOutputSet() to
+					// start with a "copy" of the fields read from the image.
+					 outputSet = exif.getOutputSet();
+				}
+			}
+
+			if(null==outputSet)
+				outputSet =  new TiffOutputSet();
+
+			{
+				// Example of how to remove a single tag/field.
+				//
+				// Note that this approach is crude: Exif data is organized in
+				// directories.  The same tag/field may appear in more than one
+				// directory.
+				TiffOutputField aperture = outputSet
+						.findField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
+				if (null != aperture)
+				{
+					// set contains aperture tag/field.
+					outputSet
+							.removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
+				}
+			}
+
+			{
+				// Example of how to add a field/tag to the output set.
+				//
+				// Note that you should first remove the field/tag if it already exists
+				// in this directory.  See above.
+				//
+				// Certain fields/tags are expected in certain Exif directories;
+				// Others can occur in more than one directory (and often have a different
+				// meaning in different directories).
+				//
+				// TagInfo constants often contain a description of what directories
+				// are associated with a given tag.
+				//
+				// see org.apache.sanselan.formats.tiff.constants.AllTagConstants
+				//
+				TiffOutputField aperture = TiffOutputField.create(
+						TiffConstants.EXIF_TAG_APERTURE_VALUE,
+						outputSet.byteOrder, new Double(0.3));
+				TiffOutputDirectory exifDirectory = outputSet
+						.getOrCreateExifDirectory();
+				exifDirectory.add(aperture);
+			}
+
+			{
+				// Example of how to add/update GPS info to output set.
+
+				// New York City
+				double longitude = -74.0; // 74 degrees W (in Degrees East)
+				double latitude = 40 + 43 / 60.0; // 40 degrees N (in Degrees North)
+
+				outputSet.setGPSInDegrees(longitude, latitude);
+			}
+
+			//			printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DATE_TIME);
+
+			os = new FileOutputStream(dst);
+			os = new BufferedOutputStream(os);
+
+			new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,
+					outputSet);
+		}
+		finally
+		{
+			if (os != null)
+				try
+				{
+					os.close();
+				}
+				catch (IOException e)
+				{
+
+				}
+		}
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/examples/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java
------------------------------------------------------------------------------
    svn:eol-style = native