本文整理汇总了Java中org.imgscalr.Scalr.Mode方法的典型用法代码示例。如果您正苦于以下问题:Java Scalr.Mode方法的具体用法?Java Scalr.Mode怎么用?Java Scalr.Mode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.imgscalr.Scalr
的用法示例。
在下文中一共展示了Scalr.Mode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setScaledImage
import org.imgscalr.Scalr; //导入方法依赖的package包/类
private void setScaledImage(final int largeur, final int hauteur, final Scalr.Mode mode) {
if(largeur<=0 || hauteur<=0) return;
if(this.getImageLoadStatus()==MediaTracker.COMPLETE) {
if(largeurInitiale<=0) {largeurInitiale=this.getIconWidth();}
if(hauteurInitiale<=0) {hauteurInitiale=this.getIconHeight();}
this.setImage(ImageTools.getScaledInstance(ImageTools.imageToBufferedImage(this.getImage()), largeur, hauteur, ImageTools.Quality.OPTIMAL, mode));
}
getImage().getWidth(new ImageObserver() {
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
if((infoflags & ALLBITS)!=0) {
if(Icone.this.largeurInitiale<=0) {Icone.this.largeurInitiale=Icone.this.getIconWidth();}
if(Icone.this.hauteurInitiale<=0) {Icone.this.hauteurInitiale=Icone.this.getIconHeight();}
Icone.this.setImage(ImageTools.getScaledInstance(ImageTools.imageToBufferedImage(Icone.this.getImage()), largeur, hauteur, ImageTools.Quality.OPTIMAL, mode));
return false;
}
return true;
}
});
// this.setImage(this.getImage().getScaledInstance(largeur, hauteur, Image.SCALE_SMOOTH));
}
示例2: generateImageSizes
import org.imgscalr.Scalr; //导入方法依赖的package包/类
protected void generateImageSizes(U uploaded, String path) {
try {
File originalImageFile = new File(path);
BufferedImage image = ImageIO.read(originalImageFile);
if (image == null) {
throw new ClientException("Could not interpret uploaded file as a valid image file.");
}
hydrateHeightAndWidth(uploaded, image);
if (uploaded.getWidth() > 60) {
createResized(uploaded, image, path, 120, 60, "thumb");
}
if (uploaded.getWidth() > 250) {
createResized(uploaded, image, path, 550, 250, "small");
}
if (uploaded.getWidth() > 900) {
createResized(uploaded, image, path, 1600, 900, "medium");
}
if (Settings.instance().getUserUploads().getResizeImagesToMax() > 0) {
Scalr.Mode scaleMode = Scalr.Mode.FIT_TO_WIDTH;
if (uploaded.getWidth() > Settings.instance().getUserUploads().getResizeImagesToMax()) {
createResized(
uploaded,
image,
path,
Settings.instance().getUserUploads().getResizeImagesToMax(),
Settings.instance().getUserUploads().getResizeImagesToMax(),
"org",
scaleMode
);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例3: resizeAndCropCenter
import org.imgscalr.Scalr; //导入方法依赖的package包/类
private static BufferedImage resizeAndCropCenter(final BufferedImage image, final int width, final int height) {
final boolean verticalCrop = ((double) image.getWidth()) / ((double) image.getHeight()) < ((double) width) / ((double) height);
final Scalr.Mode mode = verticalCrop ? Scalr.Mode.FIT_TO_WIDTH : Scalr.Mode.FIT_TO_HEIGHT;
final BufferedImage resized = Scalr.resize(image, QUALITY_SETTING, mode, width, height);
final int dx = verticalCrop ? 0 : (resized.getWidth() - width) / 2;
final int dy = !verticalCrop ? 0 : (resized.getHeight() - height) / 2;
return Scalr.crop(resized, dx, dy, width, height);
}
示例4: getScaledInstance
import org.imgscalr.Scalr; //导入方法依赖的package包/类
/**
* Retourne une image aux dimensions passées en paramètre.
*
* @param original l'image originale à redimensionner
* @param largeur la nouvelle largeur
* @param hauteur la nouvelle hauteur
* @param quality la qualité du redimensionnement, rapide ou de qualité
* @return l'image originale redimensionnée
*/
public static BufferedImage getScaledInstance(BufferedImage original, int largeur, int hauteur, Quality q, Scalr.Mode mode) {
Scalr.Method method;
switch (q) {
case AUTO:method=Scalr.Method.AUTOMATIC;break;
case DEFAULT:method=Scalr.Method.BALANCED;break;
case FAST:method=Scalr.Method.SPEED;break;
case HIGH:method=Scalr.Method.QUALITY;break;
case OPTIMAL:method=Scalr.Method.ULTRA_QUALITY;break;
default:method=Scalr.Method.BALANCED;
}
return Scalr.resize(original, method, Scalr.Mode.FIT_EXACT, largeur, hauteur);
}
示例5: createResized
import org.imgscalr.Scalr; //导入方法依赖的package包/类
public void createResized(U uploaded, BufferedImage image, String orgPath, int targetHeight, int targetWidth, String postfix, Scalr.Mode scalrMode) throws IOException {
String imageFormat = uploaded.getExtension();
BufferedImage scaledImg = Scalr.resize(image, Scalr.Method.QUALITY, scalrMode,
targetWidth, targetHeight, Scalr.OP_ANTIALIAS);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int height = scaledImg.getHeight();
int width = scaledImg.getWidth();
ImageIO.write(scaledImg, imageFormat, baos);
baos.flush();
byte[] scaledImageInByte = baos.toByteArray();
baos.close();
String relativePath = FilenameUtils.removeExtension(uploaded.getCloudKey());
if (!"org".equals(postfix)) {
relativePath = relativePath + "." + postfix;
}
relativePath = relativePath + "." + uploaded.getExtension();
String thumbnailPath = this.uploadsFolder + relativePath;
Log.info("Write all byptes to {0}", thumbnailPath);
FileUtils.writeAllBytes(scaledImageInByte, new File(thumbnailPath));
Long sizeBytes = new File(thumbnailPath).length();
//String url = "{cdnUrl}/st-publisher/files/view/" + uploaded.getSecret() + "/" + uploaded.getId() + "/" + postfix + "?ts=" + DateUtils.mils();
String url = makeRawUrlForFile(uploaded, postfix);
if (postfix.equals("thumb")) {
uploaded.setThumbCloudKey(relativePath);
uploaded.setThumbRawUrl(url);
uploaded.setThumbHeight(height);
uploaded.setThumbWidth(width);
} else if (postfix.equals("small")) {
uploaded.setSmallCloudKey(relativePath);
uploaded.setSmallRawUrl(url);
uploaded.setSmallHeight(height);
uploaded.setSmallWidth(width);
} else if (postfix.equals("medium")) {
uploaded.setMediumCloudKey(relativePath);
uploaded.setMediumRawUrl(url);
uploaded.setMediumHeight(height);
uploaded.setMediumWidth(width);
} else if (postfix.equals("org")) {
uploaded.setCloudKey(relativePath);
uploaded.setRawUrl(url);
uploaded.setSizeBytes(sizeBytes);
uploaded.setHeight(height);
uploaded.setWidth(width);
}
//return scaledImageInByte;
}
示例6: resizeProportional
import org.imgscalr.Scalr; //导入方法依赖的package包/类
private static BufferedImage resizeProportional(BufferedImage image, int width, int height) {
final boolean fitToHeight = ((double) image.getWidth()) / ((double) image.getHeight()) < ((double) width) / ((double) height);
final Scalr.Mode mode = fitToHeight ? Scalr.Mode.FIT_TO_HEIGHT : Scalr.Mode.FIT_TO_WIDTH;
return Scalr.resize(image, QUALITY_SETTING, mode, Math.min(width, height), Math.min(width, height));
}