本文整理汇总了Java中org.im4java.core.IdentifyCmd类的典型用法代码示例。如果您正苦于以下问题:Java IdentifyCmd类的具体用法?Java IdentifyCmd怎么用?Java IdentifyCmd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IdentifyCmd类属于org.im4java.core包,在下文中一共展示了IdentifyCmd类的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;
}
开发者ID:hailin0,项目名称:im4java-util,代码行数:32,代码来源:ImageUtil.java
示例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
}
}
开发者ID:e-ucm,项目名称:ead,代码行数:39,代码来源:ImgMagickUtils.java
示例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;
}
开发者ID:lklong,项目名称:imageweb,代码行数:46,代码来源:ImageUtil.java
注:本文中的org.im4java.core.IdentifyCmd类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论