本文整理汇总了Java中com.mortennobel.imagescaling.DimensionConstrain类的典型用法代码示例。如果您正苦于以下问题:Java DimensionConstrain类的具体用法?Java DimensionConstrain怎么用?Java DimensionConstrain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DimensionConstrain类属于com.mortennobel.imagescaling包,在下文中一共展示了DimensionConstrain类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.mortennobel.imagescaling.DimensionConstrain; //导入依赖的package包/类
@Override
public void execute(ElfinderStorage elfinderStorage, HttpServletRequest request, HttpServletResponse response) throws Exception {
String target = request.getParameter("target");
VolumeHandler fsi = super.findTarget(elfinderStorage, target);
final DateTime dateTime = new DateTime();
final String pattern = "d MMM yyyy HH:mm:ss 'GMT'";
final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(pattern);
try (InputStream is = fsi.openInputStream()) {
BufferedImage image = ImageIO.read(is);
int width = 80;
ResampleOp rop = new ResampleOp(DimensionConstrain.createMaxDimension(width, -1));
rop.setNumberOfThreads(4);
BufferedImage b = rop.filter(image, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(b, "png", baos);
response.setHeader("Last-Modified", dateTimeFormatter.print(dateTime));
response.setHeader("Expires", dateTimeFormatter.print(dateTime.plusYears(2)));
ImageIO.write(b, "png", response.getOutputStream());
}
}
示例2: resizeImageToDINA4WithDPI
import com.mortennobel.imagescaling.DimensionConstrain; //导入依赖的package包/类
private static BufferedImage resizeImageToDINA4WithDPI(BufferedImage origImage, int targetDpiX, int targetDpiY,
int origDpiX, int origDpiY, float scaleDown) {
float targetRatioX = (float)Consts.millisToPixels(Consts.A4_W_MM, targetDpiX)/origImage.getWidth();
float targetRatioY = (float)Consts.millisToPixels(Consts.A4_H_MM, targetDpiY)/origImage.getHeight();
float targetRatio = Math.min(1.0f, Math.min(targetRatioX, targetRatioY)/scaleDown);
Logger.getLogger(ImageHelper.class.getName()).log(Level.INFO,
"Resizing BufferedImage (px) --- "+
"Original dimensions: ("+Integer.toString(origImage.getWidth())+
","+Integer.toString(origImage.getHeight())+")"+
" - Fraction: ("+Float.toString(targetRatioX)+","+Float.toString(targetRatioY)+")"+
" - Using ratio: "+Float.toString(targetRatio));
ResampleOp resampleOp = new ResampleOp(DimensionConstrain.createRelativeDimension(targetRatio, targetRatio));
resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
return resampleOp.filter(origImage, null);
}
示例3: execute
import com.mortennobel.imagescaling.DimensionConstrain; //导入依赖的package包/类
@Override
public void execute(FsService fsService, HttpServletRequest request,
HttpServletResponse response, ServletContext servletContext)
throws Exception
{
String target = request.getParameter("target");
FsItemEx fsi = super.findItem(fsService, target);
InputStream is = fsi.openInputStream();
BufferedImage image = ImageIO.read(is);
int width = fsService.getServiceConfig().getTmbWidth();
ResampleOp rop = new ResampleOp(DimensionConstrain.createMaxDimension(
width, -1));
rop.setNumberOfThreads(4);
BufferedImage b = rop.filter(image, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(b, "png", baos);
byte[] bytesOut = baos.toByteArray();
is.close();
response.setHeader("Last-Modified",
DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360)
.toGMTString());
response.setHeader("Expires",
DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360)
.toGMTString());
ImageIO.write(b, "png", response.getOutputStream());
}
示例4: ImprovedMultistepRescaleOp
import com.mortennobel.imagescaling.DimensionConstrain; //导入依赖的package包/类
public ImprovedMultistepRescaleOp(int dstWidth, int dstHeight, Object renderingHintInterpolation) {
this(DimensionConstrain.createAbsolutionDimension(dstWidth, dstHeight), renderingHintInterpolation);
}
示例5: returnImage
import com.mortennobel.imagescaling.DimensionConstrain; //导入依赖的package包/类
private void returnImage(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) throws IOException {
int width = (!StringUtils.isEmpty(request.getParameter("w"))) ? Integer.valueOf(request.getParameter("w")) : 150;
int height = (!StringUtils.isEmpty(request.getParameter("h"))) ? Integer.valueOf(request.getParameter("h")) : 100;
Boolean real = request.getParameter("r") != null;
BufferedImage image = null;
BufferedImage b = null;
filePath = StringUtil.addSuffixIfNotAlready(filePath, File.separator);
File picture = new File(filePath + tc.getFileName());
LOG.debug("Accessing File : " + picture.getAbsolutePath());
try {
if (real) {
b = ImageIO.read(picture);
ImageIO.write(b, "png", response.getOutputStream());
} else {
image = ImageIO.read(picture);
// We test if file is too thin or too long. That prevent 500 error in case files are not compatible with resize. In that case, we crop the file.
if ((image.getHeight() * width / image.getWidth() < 10) || (image.getWidth() * height / image.getHeight() < 15)) {
LOG.debug("Image is too big of thin. Target Height : " + image.getHeight() * width / image.getWidth() + " Target Width : " + image.getWidth() * height / image.getHeight());
b = ImageIO.read(picture);
int minwidth = width;
if (width > image.getWidth()) {
minwidth = image.getWidth();
}
int minheight = height;
if (height > image.getHeight()) {
minheight = image.getHeight();
}
BufferedImage crop = ((BufferedImage) b).getSubimage(0, 0, minwidth, minheight);
b = crop;
response.setHeader("Format-Status", "ERROR");
response.setHeader("Format-Status-Message", "Image Crop from : " + image.getWidth() + "X" + image.getHeight() + " to : " + minwidth + "X" + minheight);
} else {
ResampleOp rop = new ResampleOp(DimensionConstrain.createMaxDimension(width, height, true));
rop.setNumberOfThreads(4);
b = rop.filter(image, null);
response.setHeader("Format-Status", "OK");
}
}
} catch (IOException e) {
}
response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());
response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());
response.setHeader("Type", "PNG");
response.setHeader("Description", tc.getFileDesc());
ImageIO.write(b, "png", response.getOutputStream());
}
示例6: processRequest
import com.mortennobel.imagescaling.DimensionConstrain; //导入依赖的package包/类
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
* @throws CerberusException
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, CerberusException {
String charset = request.getCharacterEncoding();
String application = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("application"), "", charset);
String object = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("object"), "", charset);
int width = (!StringUtils.isEmpty(request.getParameter("w"))) ? Integer.valueOf(request.getParameter("w")) : -1;
int height = (!StringUtils.isEmpty(request.getParameter("h"))) ? Integer.valueOf(request.getParameter("h")) : -1;
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IApplicationObjectService applicationObjectService = appContext.getBean(IApplicationObjectService.class);
BufferedImage image = applicationObjectService.readImageByKey(application,object);
BufferedImage b;
if(image != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
/**
* If width and height not defined, get image in real size
*/
if (width ==-1 && height==-1) {
b = image;
} else {
ResampleOp rop = new ResampleOp(DimensionConstrain.createMaxDimension(width, height, true));
rop.setNumberOfThreads(4);
b = rop.filter(image, null);
}
ImageIO.write(b, "png", baos);
// byte[] bytesOut = baos.toByteArray();
}else{
// create a buffered image
ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
b = ImageIO.read(bis);
bis.close();
}
response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());
response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());
ImageIO.write(b, "png", response.getOutputStream());
}