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 LLJTranTutorial {
請問下面的ip指的是檔案嗎
如果是檔案的話要怎麼改它的路徑
如果這檔案是要讀C://b.jpg
要怎麼改好讓她讀到
如果能的話請告訴我這些程式大概是在做什麼東西
private static byte[] getThumbnailImage(InputStream ip) throws IOException
{
ImageReader reader;
ImageInputStream iis = ImageIO.createImageInputStream(ip);
reader = (ImageReader) ImageIO.getImageReaders(iis).next();
reader.setInput(iis);
BufferedImage image = reader.read(0);
iis.close();
// Scale the image to around 160x120/120x160 pixels, may not conform
// exactly to Thumbnail requirements of 160x120.
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); // Write Out the Scaled Image to a ByteArrayOutputStream and return the
// bytes
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(2048);
String format = "JPG";
ImageIO.write(image, format, byteStream); return byteStream.toByteArray();
} /**
* This example demonstrates basic Lossless Transformation.<p>
*
* Usage: java LLJTranTutorial <inputFile> <outputFile> <transformOperation><p>
*
* The program does the following:<p>
*
* 1. Reads the Image from inputFile<br>
* 2. Transforms it with the specified transformOperation except CROP<br>
* 3. Saves a vertical mirror of this transformed Image into vmirror.jpg
* removing any Exif header information<br>
* 4. Saves the transormed Image (The Vertical Mirroring is not included) to
* outputFile
*/
public static void main1(String[] args) throws Exception {
int op = 0; if(args.length != 3 || (op = Integer.parseInt(args[2])) < 0 || op > 7)
{
if(args.length == 3)
System.out.println("Invalid Transform Operation: " + op); System.out.println("Usage: java LLJTranTutorial <inputFile> <outputFile> <transformOperation>\n");
System.out.println(" Use the following codes for <transformOperation>:");
System.out.println(" 0: NONE");
System.out.println(" 1: FLIP_H");
System.out.println(" 2: FLIP_V");
System.out.println(" 3: TRANSPOSE");
System.out.println(" 4: TRANSVERSE");
System.out.println(" 5: ROTATE 90 degrees clockwise");
System.out.println(" 6: ROTATE 180 degrees clockwise");
System.out.println(" 7: ROTATE 270 degrees clockwise");
System.out.println("Also creates vmirror.jpg, Vertical mirror of outputFile without Exif");
System.exit(1);
} // Raise the Debug Level which is normally LEVEL_INFO. Only Warning
// messages will be printed by MediaUtil.
Log.debugLevel = Log.LEVEL_WARNING; // 1. Initialize LLJTran and Read the entire Image including Appx ers
LLJTran llj = new LLJTran(new File(args[0]));
// If you pass the 2nd parameter as false, Exif information is not
// loaded and hence will not be written.
llj.read(LLJTran.READ_ALL, true); // 2. Transform the image using default options along with
// transformation of the Orientation tags. Try other combinations of
// LLJTran_XFORM.. flags. Use a jpeg with partial MCU (partialMCU.jpg)
// for testing LLJTran.XFORM_TRIM and LLJTran.XFORM_ADJUST_EDGES
int options = LLJTran.OPT_DEFAULTS | LLJTran.OPT_XFORM_ORIENTATION;
llj.transform(op, options); // 3. Save the Vertical mirror of the Transformed image without Exif
// header.
OutputStream out = new BufferedOutputStream(
new FileOutputStream("vmirror.jpg"));
// Turn off OPT_WRITE_APPXS flag to Skip writing Exif.
// Also try writing with Appxs
options = LLJTran.OPT_DEFAULTS & ~LLJTran.OPT_WRITE_APPXS;
// Save with vertical transformation without changing the llj image.
llj.transform(out, LLJTran.FLIP_V, options);
out.close(); // 4. Save the Image which is already transformed as specified by the
// input transformation in Step 2, along with the Exif header.
out = new BufferedOutputStream(
new FileOutputStream(args[1]));
llj.save(out, LLJTran.OPT_WRITE_ALL);
out.close(); // Cleanup
llj.freeMemory();
}
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 LLJTranTutorial {
請問下面的ip指的是檔案嗎
如果是檔案的話要怎麼改它的路徑
如果這檔案是要讀C://b.jpg
要怎麼改好讓她讀到
如果能的話請告訴我這些程式大概是在做什麼東西
private static byte[] getThumbnailImage(InputStream ip) throws IOException
{
ImageReader reader;
ImageInputStream iis = ImageIO.createImageInputStream(ip);
reader = (ImageReader) ImageIO.getImageReaders(iis).next();
reader.setInput(iis);
BufferedImage image = reader.read(0);
iis.close();
// Scale the image to around 160x120/120x160 pixels, may not conform
// exactly to Thumbnail requirements of 160x120.
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); // Write Out the Scaled Image to a ByteArrayOutputStream and return the
// bytes
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(2048);
String format = "JPG";
ImageIO.write(image, format, byteStream); return byteStream.toByteArray();
} /**
* This example demonstrates basic Lossless Transformation.<p>
*
* Usage: java LLJTranTutorial <inputFile> <outputFile> <transformOperation><p>
*
* The program does the following:<p>
*
* 1. Reads the Image from inputFile<br>
* 2. Transforms it with the specified transformOperation except CROP<br>
* 3. Saves a vertical mirror of this transformed Image into vmirror.jpg
* removing any Exif header information<br>
* 4. Saves the transormed Image (The Vertical Mirroring is not included) to
* outputFile
*/
public static void main1(String[] args) throws Exception {
int op = 0; if(args.length != 3 || (op = Integer.parseInt(args[2])) < 0 || op > 7)
{
if(args.length == 3)
System.out.println("Invalid Transform Operation: " + op); System.out.println("Usage: java LLJTranTutorial <inputFile> <outputFile> <transformOperation>\n");
System.out.println(" Use the following codes for <transformOperation>:");
System.out.println(" 0: NONE");
System.out.println(" 1: FLIP_H");
System.out.println(" 2: FLIP_V");
System.out.println(" 3: TRANSPOSE");
System.out.println(" 4: TRANSVERSE");
System.out.println(" 5: ROTATE 90 degrees clockwise");
System.out.println(" 6: ROTATE 180 degrees clockwise");
System.out.println(" 7: ROTATE 270 degrees clockwise");
System.out.println("Also creates vmirror.jpg, Vertical mirror of outputFile without Exif");
System.exit(1);
} // Raise the Debug Level which is normally LEVEL_INFO. Only Warning
// messages will be printed by MediaUtil.
Log.debugLevel = Log.LEVEL_WARNING; // 1. Initialize LLJTran and Read the entire Image including Appx ers
LLJTran llj = new LLJTran(new File(args[0]));
// If you pass the 2nd parameter as false, Exif information is not
// loaded and hence will not be written.
llj.read(LLJTran.READ_ALL, true); // 2. Transform the image using default options along with
// transformation of the Orientation tags. Try other combinations of
// LLJTran_XFORM.. flags. Use a jpeg with partial MCU (partialMCU.jpg)
// for testing LLJTran.XFORM_TRIM and LLJTran.XFORM_ADJUST_EDGES
int options = LLJTran.OPT_DEFAULTS | LLJTran.OPT_XFORM_ORIENTATION;
llj.transform(op, options); // 3. Save the Vertical mirror of the Transformed image without Exif
// header.
OutputStream out = new BufferedOutputStream(
new FileOutputStream("vmirror.jpg"));
// Turn off OPT_WRITE_APPXS flag to Skip writing Exif.
// Also try writing with Appxs
options = LLJTran.OPT_DEFAULTS & ~LLJTran.OPT_WRITE_APPXS;
// Save with vertical transformation without changing the llj image.
llj.transform(out, LLJTran.FLIP_V, options);
out.close(); // 4. Save the Image which is already transformed as specified by the
// input transformation in Step 2, along with the Exif header.
out = new BufferedOutputStream(
new FileOutputStream(args[1]));
llj.save(out, LLJTran.OPT_WRITE_ALL);
out.close(); // Cleanup
llj.freeMemory();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货