本文整理汇总了Java中watermarker.impl.DefaultWatermarker类的典型用法代码示例。如果您正苦于以下问题:Java DefaultWatermarker类的具体用法?Java DefaultWatermarker怎么用?Java DefaultWatermarker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultWatermarker类属于watermarker.impl包,在下文中一共展示了DefaultWatermarker类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPreviewWaterMark
import watermarker.impl.DefaultWatermarker; //导入依赖的package包/类
public static String setPreviewWaterMark(HttpServletRequest request, HttpServletResponse response) {
Map<String, ? extends Object> context = UtilGenerics.checkMap(request.getParameterMap());
Delegator delegator = (Delegator) request.getAttribute("delegator");
String imageServerPath = FlexibleStringExpander.expandString(EntityUtilProperties.getPropertyValue("catalog", "image.management.path", delegator), context);
String productId = request.getParameter("productId");
String imageName = request.getParameter("imageName");
String text = request.getParameter("text");
String opacity = request.getParameter("opacity");
String x = request.getParameter("x");
String y = request.getParameter("y");
String width = request.getParameter("width");
String count = request.getParameter("count");
String fontColor = request.getParameter("fontColor");
String fontSize = request.getParameter("fontSize");
String dirPath = "/preview/";
File dir = new File(imageServerPath + dirPath);
if (!dir.exists()) {
boolean createDir = dir.mkdir();
if (!createDir) {
request.setAttribute("_ERROR_MESSAGE_", "Cannot create directory.");
return "error";
}
}
BigDecimal opa = new BigDecimal(opacity);
DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.applyPattern("0.00");
BigDecimal positionX = new BigDecimal(decimalFormat.format(Float.parseFloat(x)));
BigDecimal positionY = new BigDecimal(decimalFormat.format(Float.parseFloat(y)));
BigDecimal picWidth = new BigDecimal(decimalFormat.format(Float.parseFloat(width)));
File file = new File(imageServerPath + "/preview/" + "/previewImage" + count + ".jpg");
file.delete();
BigDecimal widthBase = new BigDecimal(600.00);
Integer currentPic = Integer.parseInt(count);
int nextPic = currentPic.intValue() + 1;
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opa.floatValue());
WatermarkSettings position = new WatermarkSettings();
position.setX(positionX.floatValue());
position.setY(positionY.floatValue());
Color graphicsColor = setFontColor(fontColor);
Font graphicsFont = setFontSize(fontSize, picWidth.divide(widthBase, 2));
WatermarkerSettings watermarkerSettings = WatermarkerSettings.DEFAULT;
watermarkerSettings.setGraphicsColor(graphicsColor);
watermarkerSettings.setGraphicsFont(graphicsFont);
watermarkerSettings.setWatermarkSettings(position);
watermarkerSettings.setAlphaComposite(alphaComposite);
try {
URL imageUrl = new URL("file:" + imageServerPath + "/" + productId + "/" + imageName);
File outputImageFile = new File(imageServerPath + "/preview/" + "/previewImage" + nextPic + ".jpg");
OutputStream outputStream = new FileOutputStream(outputImageFile);
new DefaultWatermarker().watermark(imageUrl, text, outputStream, watermarkerSettings);
} catch (Exception e) {
String errMsg = "Error from setPreviewWaterMark";
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
return "success";
}
示例2: setPreviewWaterMark
import watermarker.impl.DefaultWatermarker; //导入依赖的package包/类
public static String setPreviewWaterMark(HttpServletRequest request, HttpServletResponse response) {
Map<String, ? extends Object> context = UtilGenerics.checkMap(request.getParameterMap());
String imageServerPath = FlexibleStringExpander.expandString(UtilProperties.getPropertyValue("catalog", "image.management.path"), context);
String productId = request.getParameter("productId");
String imageName = request.getParameter("imageName");
String text = request.getParameter("text");
String opacity = request.getParameter("opacity");
String x = request.getParameter("x");
String y = request.getParameter("y");
String width = request.getParameter("width");
String count = request.getParameter("count");
String fontColor = request.getParameter("fontColor");
String fontSize = request.getParameter("fontSize");
String dirPath = "/preview/";
File dir = new File(imageServerPath + dirPath);
if (!dir.exists()) {
boolean createDir = dir.mkdir();
if (!createDir) {
request.setAttribute("_ERROR_MESSAGE_", "Cannot create directory.");
return "error";
}
}
BigDecimal opa = new BigDecimal(opacity);
DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.applyPattern("0.00");
BigDecimal positionX = new BigDecimal(decimalFormat.format(Float.parseFloat(x)));
BigDecimal positionY = new BigDecimal(decimalFormat.format(Float.parseFloat(y)));
BigDecimal picWidth = new BigDecimal(decimalFormat.format(Float.parseFloat(width)));
File file = new File(imageServerPath + "/preview/" + "/previewImage" + count + ".jpg");
file.delete();
BigDecimal widthBase = new BigDecimal(600.00);
Integer currentPic = Integer.parseInt(count);
int nextPic = currentPic.intValue() + 1;
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opa.floatValue());
WatermarkSettings position = new WatermarkSettings();
position.setX(positionX.floatValue());
position.setY(positionY.floatValue());
Color graphicsColor = setFontColor(fontColor);
Font graphicsFont = setFontSize(fontSize, picWidth.divide(widthBase, 2));
WatermarkerSettings watermarkerSettings = WatermarkerSettings.DEFAULT;
watermarkerSettings.setGraphicsColor(graphicsColor);
watermarkerSettings.setGraphicsFont(graphicsFont);
watermarkerSettings.setWatermarkSettings(position);
watermarkerSettings.setAlphaComposite(alphaComposite);
try {
URL imageUrl = new URL("file:" + imageServerPath + "/" + productId + "/" + imageName);
File outputImageFile = new File(imageServerPath + "/preview/" + "/previewImage" + nextPic + ".jpg");
OutputStream outputStream = new FileOutputStream(outputImageFile);
new DefaultWatermarker().watermark(imageUrl, text, outputStream, watermarkerSettings);
} catch (Exception e) {
String errMsg = "Error from setPreviewWaterMark";
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
return "success";
}