本文整理汇总了Java中org.im4java.core.IMOperation.addImage方法的典型用法代码示例。如果您正苦于以下问题:Java IMOperation.addImage方法的具体用法?Java IMOperation.addImage怎么用?Java IMOperation.addImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.im4java.core.IMOperation
的用法示例。
在下文中一共展示了IMOperation.addImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rotateImage
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
/**
* This method is used to rotate the image present at the image path given with default degree of rotation.
* @param imagePath {@link String}
* @param degreeOfRotation double
* @throws DCMAApplicationException if any exception occurs during rotation of image.
*/
public void rotateImage(String imagePath, double degreeOfRotation) throws DCMAApplicationException {
File fImagePath = new File(imagePath);
if(!fImagePath.exists()){
throw new DCMABusinessException("File does not exist filename="+fImagePath);
}
ConvertCmd convertcmd = new ConvertCmd();
IMOperation operation = new IMOperation();
operation.rotate(degreeOfRotation);
operation.addImage();
operation.addImage();
Object[] listOfFiles = {imagePath,imagePath};
try {
convertcmd.run(operation, listOfFiles);
} catch (Exception e) {
LOGGER.error("Problem rotating image "+imagePath);
throw new DCMAApplicationException("Unable to rotate Image", e);
}
}
示例2: run_chokes_whenServiceChokes
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Test
public void run_chokes_whenServiceChokes() throws Exception {
// create command
final String command = "bad";
sut = new GMBatchCommand(service, command);
// create the operation, add images and operators/options
IMOperation op = new IMOperation();
op.addImage(SOURCE_IMAGE);
op.resize(800, 600);
op.addImage(TARGET_IMAGE);
final String message = "bad command";
when(service.execute(anyListOf(String.class))).thenThrow(new GMException(message));
exception.expect(CommandException.class);
exception.expectMessage(message);
// execute the operation
sut.run(op);
}
示例3: 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;
}
示例4: addTextWatermark
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
/**
* 文字水印
*
* @param srcImagePath 源图片路径
* @param destImagePath 目标图片路径
* @param content 文字内容(不支持汉字)
* @throws Exception
*/
public static void addTextWatermark(String srcImagePath, String destImagePath, String content)
throws Exception {
IMOperation op = new IMOperation();
op.font("微软雅黑");
// 文字方位-东南
op.gravity("southeast");
// 文字信息
op.pointsize(18).fill("#BCBFC8").draw("text 10,10 " + content);
// 原图
op.addImage(srcImagePath);
// 目标
op.addImage(createDirectory(destImagePath));
ImageCommand cmd = getImageCommand(CommandType.convert);
cmd.run(op);
}
示例5: addImgWatermark
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
/**
* 图片水印
*
* @param srcImagePath 源图片路径
* @param destImagePath 目标图片路径
* @param dissolve 透明度(0-100)
* @throws Exception
*/
public static void addImgWatermark(String srcImagePath, String destImagePath, Integer dissolve)
throws Exception {
// 原始图片信息
BufferedImage buffimg = ImageIO.read(new File(srcImagePath));
int w = buffimg.getWidth();
int h = buffimg.getHeight();
IMOperation op = new IMOperation();
// 水印图片位置
op.geometry(watermarkImage.getWidth(null), watermarkImage.getHeight(null), w
- watermarkImage.getWidth(null) - 10, h - watermarkImage.getHeight(null) - 10);
// 水印透明度
op.dissolve(dissolve);
// 水印
op.addImage(watermarkImagePath);
// 原图
op.addImage(srcImagePath);
// 目标
op.addImage(createDirectory(destImagePath));
ImageCommand cmd = getImageCommand(CommandType.compositecmd);
cmd.run(op);
}
示例6: rotate
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
/**
* 旋转图片
*
* @param srcImagePath 源图片路径
* @param destImagePath 目标图片路径
* @param angle 旋转的角度
* @return
* @throws Exception
*/
public static void rotate(String srcImagePath, String destImagePath, Double angle)
throws Exception {
File sourceFile = new File(srcImagePath);
if (!sourceFile.exists() || !sourceFile.canRead() || !sourceFile.isFile()) {
return;
}
BufferedImage buffimg = ImageIO.read(sourceFile);
int w = buffimg.getWidth();
int h = buffimg.getHeight();
// 目标图片
// if (w > h) { //如果宽度不大于高度则旋转过后图片会变大
ImageCommand cmd = getImageCommand(CommandType.convert);
IMOperation operation = new IMOperation();
operation.addImage(srcImagePath);
operation.rotate(angle);
operation.addImage(destImagePath);
cmd.run(operation);
// }
}
示例7: generatePNGForImage
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
public void generatePNGForImage(File imagePath) throws DCMAApplicationException {
ConvertCmd convertcmd = new ConvertCmd();
IMOperation operationPNG = new IMOperation();
operationPNG.addImage();
operationPNG.addImage();
String imageName = imagePath.getAbsolutePath();
// TODO remove hard coding _thumb.png, .png and .tif
String pngPath = imageName.substring(0, imageName.lastIndexOf(ImageMagicKConstants.DOT));
try {
String[] listOfFiles = {imageName, pngPath + FileType.PNG.getExtensionWithDot()};
convertcmd.run(operationPNG, (Object[]) listOfFiles);
} catch (Exception ex) {
LOGGER.error("Problem generating png.");
throw new DCMAApplicationException("Problem generating png.", ex);
}
}
示例8: convertWithOptions
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
public byte[] convertWithOptions(InputStream image, String options) {
String[] optionStrings = options.split(" ");
IMOperation iMOperation = new IMOperation();
iMOperation.addImage("-");
iMOperation.addRawArgs(optionStrings);
iMOperation.addImage(":-");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe(image, null);
Pipe pipeOut = new Pipe(null, byteArrayOutputStream);
ConvertCmd convertCmd = new ConvertCmd();
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
try {
convertCmd.run(iMOperation);
} catch (IOException | InterruptedException | IM4JavaException exception) {
System.err.println(exception.getMessage());
}
return byteArrayOutputStream.toByteArray();
}
示例9: convert2ImageFormat
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
public static byte[] convert2ImageFormat(InputStream image, String format) throws IOException, InterruptedException, IM4JavaException {
IMOperation iMOperation = new IMOperation();
iMOperation.addImage("-");
iMOperation.addImage( format + ":-");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe(image, null);
Pipe pipeOut = new Pipe(null, byteArrayOutputStream);
ConvertCmd convertCmd = new ConvertCmd();
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
convertCmd.run(iMOperation);
return byteArrayOutputStream.toByteArray();
}
示例10: resize
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
protected static byte[] resize(InputStream image, Integer maxWidth, Integer maxHeight, String format, boolean keepAspectRatio) throws IOException, InterruptedException, IM4JavaException {
IMOperation iMOperation = new IMOperation();
iMOperation.addImage("-");
if(!keepAspectRatio) {
iMOperation.resize(maxWidth, maxHeight, '!');
} else {
iMOperation.resize(maxWidth, maxHeight);
}
iMOperation.addImage(format + ":-");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe(image, null);
Pipe pipeOut = new Pipe(null, byteArrayOutputStream);
ConvertCmd convertCmd = new ConvertCmd();
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
convertCmd.run(iMOperation);
return byteArrayOutputStream.toByteArray();
}
示例11: crop
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
static byte[] crop(InputStream image, int width, int height, int offsetX, int offsetY, String format, int rwidth, int rheight) throws IOException, InterruptedException, IM4JavaException {
IMOperation iMOperation = new IMOperation();
iMOperation.addImage("-");
iMOperation.crop(width, height, offsetX, offsetY);
iMOperation.repage(rwidth, rheight);
iMOperation.addImage(format + ":-");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe(image, null);
Pipe pipeOut = new Pipe(null, byteArrayOutputStream);
ConvertCmd convertCmd = new ConvertCmd();
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
convertCmd.run(iMOperation);
return byteArrayOutputStream.toByteArray();
}
示例12: rotate
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
static byte[] rotate(InputStream image, double degrees, String format) throws IOException, InterruptedException, IM4JavaException {
IMOperation iMOperation = new IMOperation();
iMOperation.addImage("-");
iMOperation.rotate(degrees);
iMOperation.addImage(format + ":-");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe(image, null);
Pipe pipeOut = new Pipe(null, byteArrayOutputStream);
ConvertCmd convertCmd = new ConvertCmd();
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
convertCmd.run(iMOperation);
return byteArrayOutputStream.toByteArray();
}
示例13: run_chokes_whenErrorConsumerIsNull
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Test
@SuppressWarnings("NP_NONNULL_PARAM_VIOLATION")
public void run_chokes_whenErrorConsumerIsNull() throws Exception {
// create command
final String command = "bad";
sut = new GMBatchCommand(service, command);
// create the operation, add images and operators/options
IMOperation op = new IMOperation();
op.addImage(SOURCE_IMAGE);
op.resize(800, 600);
op.addImage(TARGET_IMAGE);
final String message = "bad command";
when(service.execute(anyListOf(String.class))).thenThrow(new GMException(message));
exception.expect(CommandException.class);
exception.expectMessage(message);
sut.setErrorConsumer(null);
// execute the operation
sut.run(op);
}
示例14: run_sendsCommandToService
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Test
public void run_sendsCommandToService() throws Exception {
// create command
final String command = "convert";
sut = new GMBatchCommand(service, command);
// create the operation, add images and operators/options
IMOperation op = new IMOperation();
op.addImage(SOURCE_IMAGE);
op.resize(800, 600);
op.addImage(TARGET_IMAGE);
// execute the operation
sut.run(op);
verify(service).execute(Arrays.asList(command, SOURCE_IMAGE, "-resize", "800x600", TARGET_IMAGE));
}
示例15: run_works_whenOutputConsumerIsNull
import org.im4java.core.IMOperation; //导入方法依赖的package包/类
@Test
@SuppressWarnings("NP_NONNULL_PARAM_VIOLATION")
public void run_works_whenOutputConsumerIsNull() throws Exception {
// create command
final String command = "convert";
sut = new GMBatchCommand(service, command);
// create the operation, add images and operators/options
IMOperation op = new IMOperation();
op.addImage(SOURCE_IMAGE);
op.resize(800, 600);
op.addImage(TARGET_IMAGE);
sut.setOutputConsumer(null);
// execute the operation
sut.run(op);
verify(service).execute(Arrays.asList(command, SOURCE_IMAGE, "-resize", "800x600", TARGET_IMAGE));
}