本文整理汇总了Java中org.im4java.core.IdentifyCmd.run方法的典型用法代码示例。如果您正苦于以下问题:Java IdentifyCmd.run方法的具体用法?Java IdentifyCmd.run怎么用?Java IdentifyCmd.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.im4java.core.IdentifyCmd
的用法示例。
在下文中一共展示了IdentifyCmd.run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getImageInfo
import org.im4java.core.IdentifyCmd; //导入方法依赖的package包/类
/**
* 获取图片信息
*
* @param srcImagePath 图片路径
* @return Map {height=, filelength=, directory=, width=, filename=}
*/
public static Map<String, Object> getImageInfo(String srcImagePath) {
IMOperation op = new IMOperation();
op.format("%w,%h,%d,%f,%b");
op.addImage(srcImagePath);
IdentifyCmd identifyCmd = (IdentifyCmd) getImageCommand(CommandType.identify);
ArrayListOutputConsumer output = new ArrayListOutputConsumer();
identifyCmd.setOutputConsumer(output);
try {
identifyCmd.run(op);
} catch (Exception e) {
e.printStackTrace();
}
ArrayList<String> cmdOutput = output.getOutput();
if (cmdOutput.size() != 1)
return null;
String line = cmdOutput.get(0);
String[] arr = line.split(",");
Map<String, Object> info = new HashMap<String, Object>();
info.put("width", Integer.parseInt(arr[0]));
info.put("height", Integer.parseInt(arr[1]));
info.put("directory", arr[2]);
info.put("filename", arr[3]);
info.put("filelength", Integer.parseInt(arr[4]));
return info;
}
示例2: showImageProperties
import org.im4java.core.IdentifyCmd; //导入方法依赖的package包/类
/**
* Prints out on console a detailed report of the characteristics and format
* of the given image. Useful for debugging weird problematic images.
*
* @param imagePath
* The path to the image to analyze
*/
public void showImageProperties(String imagePath) {
IdentifyCmd identifyCmd = new IdentifyCmd();
IMOperation op = new IMOperation();
op.verbose();
identifyCmd.setOutputConsumer(new OutputConsumer() {
@Override
public void consumeOutput(InputStream inputStream)
throws IOException {
StringBuilder out = new StringBuilder();
final Reader in = new InputStreamReader(inputStream, "UTF-8");
char[] c = new char[1024];
int length = -1;
String result = "";
while ((length = in.read(c)) != -1) {
out.append(c, 0, length);
}
in.close();
result = out.toString();
System.err.println(result);
}
});
op.addImage(imagePath);
try {
identifyCmd.run(op);
} catch (Exception e2) {
// Do nothing
}
}
示例3: getImageInfo
import org.im4java.core.IdentifyCmd; //导入方法依赖的package包/类
/**
* 获取图片基本信息
*
* @param is
* @return
* @throws IOException
* @throws InterruptedException
* @throws IM4JavaException
*
*/
public static List<Integer> getImageInfo(InputStream is) throws IOException, InterruptedException, IM4JavaException {
List<Integer> imagewh = new ArrayList<Integer>();
IMOperation op = new IMOperation();
op.format("%w,%h");// ,path:%d%f,size:%b%[EXIF:DateTimeOriginal]
op.addImage(1);
IdentifyCmd cmd = new IdentifyCmd(GraphicImageConstants.GM);
ArrayListOutputConsumer output = new ArrayListOutputConsumer();
BufferedImage img = ImageIO.read(is);
cmd.setOutputConsumer(output);
cmd.run(op, img);
ArrayList<String> cmdOutput = output.getOutput();
String[] line = cmdOutput.get(0).split(",");
Integer width = Integer.valueOf(line[0]);
Integer height = Integer.valueOf(line[1]);
imagewh.add(width);
imagewh.add(height);
return imagewh;
}