首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • ImageInputStream 問題 [无满意答案结贴]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-08-23 15:52:40 楼主
    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 &lt;inputFile&gt; &lt;outputFile&gt; &lt;transformOperation&gt; <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 markers
            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();
        }

    20  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • AWUSOFT
    • 等级:
    发表于:2008-08-23 19:07:041楼 得分:0
    不知道你所说的档案是什么意思啊.那个IP就是一个InputStream嘛.输入流.
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-08-24 16:05:132楼 得分:0
    要怎麼指定他的路徑
    我要讀取的圖片位置
    以及輸出位置
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved