根据图片尺寸分类的小程序

功能:将输入目录类所有的文件按照输入尺寸:长,宽进行筛选,生成3个文件列表:尺寸大于输入,尺寸小于输入,分析失败。

代码如下:
/**
 * 2005-05-19
 */

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageDecoder;
import com.sun.image.codec.jpeg.TruncatedFileException;

/**
 *
 * @author LEI
 *
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class ImgFilter {

    /** Automatically generated javadoc for: INT_100 */
    private static final int INT_100 = 100;

    /** Automatically generated javadoc for: INT_600 */
    private static final int INT_600 = 600;
    /** Automatically generated javadoc for: INT_800 */
    private static final int INT_800 = 800;

    /**
     * 
     */
    private static void error () {
        System.out
                .println("Too Few Argument./nImgFileter c:/images 800(width) 600(height)");
    }

    public static void main (String[] args) {
        if (args.length < 3) {
            error();
            return;
        }
        ImgFilter bot = new ImgFilter();
        bot.execute(args);
        System.out.println("--------/n");
    }

    /**
     * Check the input image size pixel(s)
     *
     * @param fp
     * @param minWidth
     * @param minHeight
     * @return
     */
    private int checkSize (String fp, int minWidth, int minHeight) {
        InputStream in = null;
        try {
            BufferedImage mImage;
            in = new FileInputStream(fp);
            JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
            mImage = decoder.decodeAsBufferedImage();
            int height = mImage.getHeight();
            int width = mImage.getWidth();
            long minSqure = minWidth * minHeight;
            long squre = width * height;
            if (width < minWidth && height < minHeight) {
                return 0;
            }
            if (squre < minSqure) {
                return 0;
            }
            return 1;
        } catch (TruncatedFileException ig1) {
            // System.err.println(fp + ": " + imgx.toString());
            return -1;
        } catch (ImageFormatException ig2) {
            return -1;
        } catch (IOException ex) {
            System.err.println(fp + ": " + ex.toString());
            return -1;
        } finally {
            try {
                in.close();
            } catch (IOException ignored) {
            }
        }
    }

    /**
     * Main entrance of the ImgFilter Class
     *
     * @param args
     */
    private void execute (String[] args) {
        String fd = args[0];
        String extend = "jpg";
        int width = INT_800, height = INT_600;
        try {
            width = Integer.parseInt(args[1]);
            height = Integer.parseInt(args[2]);
        } catch (Exception ignored) {
        }
        String[] lstFiles = retrieveDirList(fd, extend);
        if (lstFiles == null) {
            return;
        }
        int max = lstFiles.length;
        List lstOk = new ArrayList();
        List lstBad = new ArrayList();
        List lstUn = new ArrayList();
        for (int i = 0; i < lstFiles.length; i++) {
            String fn = lstFiles[i];
            String fp = fd + "/" + fn;
            int rs = checkSize(fp, width, height);
            if (rs == 1) {
                lstOk.add(fn);
            } else if (rs == 0) {
                lstBad.add(fn);
            } else {
                lstUn.add(fn);
            }
            if (i % INT_100 == 0) {
                System.out.println(i + "/" + max);
            }
        } // end for
        System.out.println(max + "/" + max);
        writeFile(fd + "/ok.lst", lstOk);
        writeFile(fd + "/fail.lst", lstBad);
        moveLstFile(fd + "/fail.lst", "small");
        writeFile(fd + "/bad.lst", lstUn);
        moveLstFile(fd + "/bad.lst", "bad");

    }
    /**
     * generate move file list
     *
     * @param fp
     * @param dirname
     */
    private void moveLstFile (String fp, String dirname) {
        BufferedReader br = null;
        StringBuffer sb = new StringBuffer();
        try {
            br = new BufferedReader(new FileReader(fp));
            String line = br.readLine();
            while (line != null) {
                sb.append("move ").append(line).append(" ").append(dirname)
                        .append("// /r/n");
                line = br.readLine();
            }
            this.writeFile(fp + ".cmd", sb.toString());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                // ignored
            }
        }

    }

    /**
     * Retrieve the spec extend name file list
     *
     * @return
     */
    private String[] retrieveDirList (String fd, String ext) {
        FilenameFilter filter = new FilenameFilter() {
            public boolean accept (File dir, String name) {
                return name.endsWith(".jpg");
            }
        };
        File dir = new File(fd);
        String[] list = dir.list(filter);
        return list;
    }

    /**
     * write input list to file
     *
     * @param string
     * @param lstUn
     */
    private void writeFile (String string, List lst) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < lst.size(); i++) {
            sb.append(lst.get(i)).append("/r/n");
        }
        writeFile(string, sb.toString());
    }

    /**
     * Write input content to input fp
     *
     * @param fp
     * @param content
     */
    private void writeFile (String fp, String content) {
        FileWriter fw = null;
        try {
            fw = new FileWriter(fp);
            fw.write(content);
        } catch (IOException e) {
            System.err.println("Write:" + fp + "failed:" + e.toString());
        } finally {
            try {
                fw.close();
            } catch (IOException e1) {
            }
        }
    }
} // eof

### 回答1: WordPress壁纸黑金小程序是一款基于WordPress平台开发的小程序,它专门为用户提供高品质的黑金壁纸资源。小程序整合了WordPress的发布和管理功能,用户可以通过小程序浏览、搜索和下载壁纸。以下是对该小程序的详细介绍: 首先,WordPress是一种简单、易于使用且功能强大的内容管理系统,它能够支持用户创建和管理自己的网站。通过在WordPress平台上建立一个壁纸专题网站,用户可以方便地发布和分享各种黑金壁纸。 其次,WordPress壁纸黑金小程序是基于用户对黑金壁纸的需求而设计的。小程序界面简洁美观,提供了方便的浏览和搜索壁纸的功能。用户可以根据自己的喜好来浏览不同的壁纸分类,如风景、动物、抽象等。同时,小程序还支持根据关键词搜索壁纸,使用户能够更快地找到自己想要的壁纸。 最后,用户在WordPress壁纸黑金小程序中可以直接下载壁纸。小程序提供了壁纸的高清下载链接,用户可以选择适合自己设备的分辨率进行下载。此外,用户还可以在小程序内分享自己喜欢的壁纸到社交媒体平台,与朋友们分享美丽的壁纸。 综上所述,WordPress壁纸黑金小程序通过整合WordPress平台的功能,为用户提供了一个便捷的浏览、搜索和下载高品质黑金壁纸的平台。用户可以随时随地通过小程序享受美丽的壁纸资源,并与他人分享自己的喜好。 ### 回答2: WordPress壁纸黑金小程序是一个基于WordPress开发的小程序,主要功能是提供高质量的壁纸资源供用户下载和使用。 首先,该小程序通过与WordPress网站的数据交互,实现了自动更新壁纸资源的功能。用户可以在小程序中浏览到各种各样的壁纸分类,例如自然风景、动物植物、抽象艺术等,每个分类下都有大量高清壁纸可供选择。 其次,小程序还提供了搜索功能,用户可以通过关键字搜索自己想要的壁纸,以方便快捷地找到心仪的图片。同时,用户还可以根据自己的喜好将壁纸加入到收藏夹中,方便日后使用。 此外,该小程序还设计了简洁美观的界面,用户可以根据自己的喜好设置壁纸的尺寸和适配方式,以确保壁纸在不同设备上的显示效果。同时,用户还可以将喜欢的壁纸分享给朋友,以展示自己的品味和个性。 总之,WordPress壁纸黑金小程序通过整合WordPress网站的壁纸资源,为用户提供了丰富多样的选择。用户可以轻松获取和下载高质量的壁纸,并通过个性化的设置和分享功能,展示自己的喜好和个性。这个小程序将为用户带来一种全新的壁纸使用体验。 ### 回答3: WordPress壁纸黑金小程序是一款基于WordPress内容管理系统开发的小程序。该小程序主要功能是为用户提供高质量的壁纸资源,其中包括黑金系列的壁纸。用户可以通过该小程序在手机上浏览和下载各种不同主题的壁纸,如自然风景、动物、建筑等等。 该小程序借助WordPress的强大功能,可以方便地管理和更新壁纸资源。管理员可以通过后台管理界面上传、编辑和删除壁纸,并设置壁纸相关的标签、分类等属性,以便用户更方便地浏览和搜索自己喜欢的壁纸。 用户可以通过小程序首页浏览精选的壁纸推荐,也可以根据自己的兴趣选择特定分类或标签进行浏览。在每张壁纸的详情页面,用户可以查看壁纸的全尺寸预览,还可以通过分享功能将壁纸分享给朋友。 此外,该小程序还提供了壁纸的下载功能,用户可以将喜欢的壁纸保存到本地相册,方便随时更换手机桌面。同时,用户还可以设置壁纸的显示方式,包括铺满、居中等多种样式,以适应不同手机屏幕的需求。 总而言之,WordPress壁纸黑金小程序通过简洁、易用的界面和强大的后台功能,为用户提供了一个方便、高质量的壁纸资源平台。无论是追求个性化还是寻找美观壁纸的用户,都可以通过该小程序找到自己满意的壁纸,并将其应用到手机上,为手机屏幕增添一份个性和美感。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值