本文整理汇总了Java中org.im4java.core.IMOperation.format方法的典型用法代码示例。如果您正苦于以下问题:Java IMOperation.format方法的具体用法?Java IMOperation.format怎么用?Java IMOperation.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.im4java.core.IMOperation
的用法示例。
在下文中一共展示了IMOperation.format方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getImageInfo
import org.im4java.core.IMOperation; //导入方法依赖的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: run_returnsResultBack
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Test
public void run_returnsResultBack() throws Exception {
final String command = "identify";
sut = new GMBatchCommand(service, command);
IMOperation op = new IMOperation();
op.ping();
final String format = "%m\n%W\n%H\n%g\n%z";
op.format(format);
op.addImage();
ArrayListOutputConsumer output = new ArrayListOutputConsumer();
sut.setOutputConsumer(output);
when(service.execute(anyListOf(String.class))).thenReturn("JPEG\n800\n600\n800x600\n0\n");
sut.run(op, SOURCE_IMAGE);
verify(service).execute(Arrays.asList(command, "-ping", "-format", format, SOURCE_IMAGE));
// ... and parse result
ArrayList<String> cmdOutput = output.getOutput();
Iterator<String> iter = cmdOutput.iterator();
assertThat(iter.next(), is("JPEG"));
assertThat(iter.next(), is("800"));
assertThat(iter.next(), is("600"));
assertThat(iter.next(), is("800x600"));
assertThat(iter.next(), is("0"));
}
示例3: fillPNGOptions
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
private static void fillPNGOptions(IMOperation op) {
op.define("png:color-type=6");
op.set("png:color-type", "6");
op.set("png:interlace-method", "0");
op.set("png:bit-depth", "8");
op.colorspace("sRGB");
op.compress("None");
op.transparentColor("None");
op.interlace("None");
op.format("png");
op.depth(8);
}
示例4: getImageInfo
import org.im4java.core.IMOperation; //导入方法依赖的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;
}