本文整理汇总了Java中org.imgscalr.Scalr.Mode类的典型用法代码示例。如果您正苦于以下问题:Java Mode类的具体用法?Java Mode怎么用?Java Mode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Mode类属于org.imgscalr.Scalr包,在下文中一共展示了Mode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadThumbnail
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
public void uploadThumbnail(String path, ByteArrayOutputStream buffer, int width, int height) throws IOException {
ByteArrayOutputStream thumbBuffer = new ByteArrayOutputStream();
BufferedImage thumb = ImageIO.read(new ByteArrayInputStream(buffer.toByteArray()));
thumb = Scalr.resize(thumb, Method.ULTRA_QUALITY,
thumb.getHeight() < thumb.getWidth() ? Mode.FIT_TO_HEIGHT : Mode.FIT_TO_WIDTH,
Math.max(width, height), Math.max(width, height), Scalr.OP_ANTIALIAS);
thumb = Scalr.crop(thumb, width, height);
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); // Needed see javadoc
param.setCompressionQuality(1.0F); // Highest quality
writer.setOutput(ImageIO.createImageOutputStream(thumbBuffer));
writer.write(thumb);
if (path.lastIndexOf('.') != -1) {
path = path.substring(0, path.lastIndexOf('.'));
}
super.put(path + "." + width + "x" + height + ".jpg", new ByteArrayInputStream(thumbBuffer.toByteArray()),
Long.valueOf(thumbBuffer.size()));
}
示例2: resizeImageWithTempThubnails
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
/**
* Metóda resizeImmaeWithTempThubnails je určeny na vytorenie obrázkovej ukáźky k danému obrazkoveho multimediálnemu súboru.
* @param pathToImage - cesta k súboru, z ktorého sa má vytvoriť obrázková ukážka
* @throws ThumbnailException Výnimka sa vyhodí pri problémoch s vytvorením ukážky
*/
public void resizeImageWithTempThubnails(String pathToImage) throws ThumbnailException{
try {
String originalPath = pathToImage;
String extension = originalPath.substring(originalPath.lastIndexOf("."), originalPath.length());
String newPath = originalPath.substring(0,originalPath.lastIndexOf(".")) + "_THUMB" + extension;
BufferedImage img = ImageIO.read(new File(originalPath));
BufferedImage scaledImg = Scalr.resize(img, Mode.AUTOMATIC, width, height);
File destFile = new File(newPath);
ImageIO.write(scaledImg, "jpg", destFile);
//System.out.println("Done resizing image: " + newPath + " " + newPath);
} catch (Exception ex) {
throw new ThumbnailException();
}
}
示例3: getBestFit
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
private BufferedImage getBestFit (BufferedImage bi, int maxWidth, int maxHeight)
{
if (bi == null)
return null ;
Mode mode = Mode.AUTOMATIC ;
int maxSize = Math.min(maxWidth, maxHeight) ;
double dh = (double)bi.getHeight() ;
if (dh > Double.MIN_VALUE)
{
double imageAspectRatio = (double)bi.getWidth() / dh ;
if (maxHeight * imageAspectRatio <= maxWidth)
{
maxSize = maxHeight ;
mode = Mode.FIT_TO_HEIGHT ;
}
else
{
maxSize = maxWidth ;
mode = Mode.FIT_TO_WIDTH ;
}
}
return Scalr.resize(bi, Method.QUALITY, mode, maxSize, Scalr.OP_ANTIALIAS) ;
}
示例4: resizeImagesWithTempThubnails
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
/**
* Metóda resizeImagesWithTempThubnails je určená na samotné vytváranie ukážok z obrázkový multimedialnych súborov, ktoré sú vložené do zonamu files.
* @throws ThumbnailException Výnimka sa vyhodí pri problémoch s vytvorením ukážky
*/
public void resizeImagesWithTempThubnails() throws ThumbnailException{
try {
for(int i = 0; i < files.size(); i++){
String originalPath = files.get(i).getPath();
String extension = originalPath.substring(originalPath.lastIndexOf("."), originalPath.length());
String newPath = originalPath.substring(0,originalPath.lastIndexOf(".")) + "_THUMB" + extension;
BufferedImage img = ImageIO.read(new File(originalPath));
BufferedImage scaledImg = Scalr.resize(img, Mode.AUTOMATIC, width, height);
File destFile = new File(newPath);
ImageIO.write(scaledImg, "jpg", destFile);
//System.out.println("Done resizing image: " + newPath + " " + newPath);
}
} catch (Exception ex) {
throw new ThumbnailException();
}
}
示例5: getThumbnail
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
public byte[] getThumbnail(InputStream inputStream, String contentType, String rotation) throws IOException {
try{
String ext = contentType.replace("image/", "").equals("jpeg")? "jpg":contentType.replace("image/", "");
BufferedImage bufferedImage = readImage(inputStream);
BufferedImage thumbImg = Scalr.resize(bufferedImage, Method.QUALITY,Mode.AUTOMATIC,
100,
100, Scalr.OP_ANTIALIAS);
//convert bufferedImage to outpurstream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(thumbImg,ext,baos);
baos.flush();
return baos.toByteArray();
}catch(Exception e){
e.printStackTrace();
return null;
}
}
示例6: scaleImage
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
private BufferedImage scaleImage(BufferedImage image, int frameWidth, int frameHeight) throws IOException {
int targetSize = 0;
Mode mode;
if (props.getScreenshotViewScaling() == ViewScaling.HORIZONTAL) {
targetSize = (int) (frameWidth * 0.97);
mode = Mode.FIT_TO_WIDTH;
} else {
targetSize = frameHeight - 160;
mode = Mode.FIT_TO_HEIGHT;
}
if (mode == Mode.FIT_TO_WIDTH && image.getWidth() <= targetSize) {
return image;
} else if (mode == Mode.FIT_TO_HEIGHT && image.getHeight() <= targetSize) {
return image;
} else {
BufferedImage scaledImage = Scalr.resize(image, mode, targetSize, Scalr.OP_ANTIALIAS);
return scaledImage;
}
}
示例7: scaleImage
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
/**
* @param buffImage
* @param scaleWidth
* @param scaleHeight
* @return
*/
public static BufferedImage scaleImage(BufferedImage buffImage, int scaleWidth, int scaleHeight) {
int imgHeight = buffImage.getHeight();
int imgWidth = buffImage.getWidth();
float destHeight = scaleHeight;
float destWidth = scaleWidth;
if ((imgWidth >= imgHeight) && (imgWidth > scaleWidth)) {
destHeight = imgHeight * ((float) scaleWidth / imgWidth);
} else if ((imgWidth < imgHeight) && (imgHeight > scaleHeight)) {
destWidth = imgWidth * ((float) scaleHeight / imgHeight);
} else {
return buffImage;
}
return Scalr.resize(buffImage, Method.BALANCED, Mode.AUTOMATIC, (int) destWidth, (int) destHeight);
}
示例8: generateImageThumbnail
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
public static BufferedImage generateImageThumbnail(InputStream imageStream) throws IOException {
try {
int idealWidth = 256;
BufferedImage source = ImageIO.read(imageStream);
if (source == null) {
return null;
}
int imgHeight = source.getHeight();
int imgWidth = source.getWidth();
float scale = (float) imgWidth / idealWidth;
int height = (int) (imgHeight / scale);
BufferedImage rescaledImage = Scalr.resize(source, Method.QUALITY,
Mode.AUTOMATIC, idealWidth, height);
if (height > 400) {
rescaledImage = rescaledImage.getSubimage(0, 0,
Math.min(256, rescaledImage.getWidth()), 400);
}
return rescaledImage;
} catch (Exception e) {
LOG.error("Generate thumbnail for error", e);
return null;
}
}
示例9: processImage
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
private static byte[] processImage(BufferedImage image, int xRatio, int yRatio, int width, int height, PictureMode pictureMode) {
final BufferedImage transformed, scaled;
switch (pictureMode) {
case FIT:
transformed = Picture.transformFit(image, xRatio, yRatio);
break;
case ZOOM:
transformed = Picture.transformZoom(image, xRatio, yRatio);
break;
default:
transformed = Picture.transformFit(image, xRatio, yRatio);
break;
}
scaled = Scalr.resize(transformed, Method.QUALITY, Mode.FIT_EXACT, width, height);
return Picture.writeImage(scaled, ContentType.PNG);
}
示例10: calculateDominantColor
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
@Override
public int[] calculateDominantColor(BufferedImage image) {
// Resize the image to 1x1 and sample the pixel
BufferedImage pixel = Scalr.resize(image, Mode.FIT_EXACT, 1, 1);
image.flush();
return pixel.getData().getPixel(0, 0, (int[]) null);
}
示例11: applyResize
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
/**
* Resize the image.
*
* @param img
* @param size
* @return
*/
private BufferedImage applyResize(BufferedImage img, Point size) {
try {
return Scalr.resize(img, Mode.FIT_EXACT, size.getX(), size.getY());
} catch (IllegalArgumentException e) {
throw error(BAD_REQUEST, "image_error_resizing_failed", e);
}
}
示例12: resize
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
private byte[] resize(byte[] picture, int height, int width, String format) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BufferedImage img = ImageIO.read(new ByteArrayInputStream(picture));
BufferedImage scaledImg = Scalr.resize(img, Mode.AUTOMATIC, height, width);
ImageIO.write(scaledImg, format, bos);
return bos.toByteArray();
} catch (IOException | RuntimeException e) {
throw new RuntimeException(e);
}
}
示例13: createThumbnail
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
public static void createThumbnail(File sourceImage, int width, int height, String extension) throws IOException {
BufferedImage img = ImageIO.read(sourceImage); // load image
BufferedImage thumbImg = Scalr.resize(img, Method.ULTRA_QUALITY,Mode.AUTOMATIC,
width, height, Scalr.OP_ANTIALIAS);
//convert bufferedImage to outpurstream
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(thumbImg,extension.toLowerCase(),os);
ImageIO.write(thumbImg, extension.toLowerCase(), sourceImage);
}
示例14: call
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
String source = ((StringValue) arguments[0].head()).getStringValue();
String target = ((StringValue) arguments[1].head()).getStringValue();
String formatName = ((StringValue) arguments[2].head()).getStringValue();
int targetSize = (int) ((Int64Value) arguments[3].head()).longValue();
try {
File targetFile = new File(target);
if (targetFile.isDirectory()) {
throw new IOException("Output file \"" + targetFile.getAbsolutePath() + "\" already exists as directory");
} else if (!targetFile.getParentFile().isDirectory() && !targetFile.getParentFile().mkdirs()) {
throw new IOException("Could not create output directory \"" + targetFile.getParentFile().getAbsolutePath() + "\"");
} else if (targetFile.isFile() && !targetFile.delete()) {
throw new IOException("Error deleting existing target file \"" + targetFile.getAbsolutePath() + "\"");
}
InputStream is;
if (source.startsWith("http")) {
is = new URL(source).openStream();
} else {
File file;
if (source.startsWith("file:")) {
file = new File(new URI(source));
} else {
file = new File(source);
}
if (!file.isFile()) {
throw new IOException("File \"" + file.getAbsolutePath() + "\" not found or not a file");
}
is = new BufferedInputStream(new FileInputStream(file));
}
try {
BufferedImage img = ImageIO.read(is);
BufferedImage scaledImg = Scalr.resize(img, Method.AUTOMATIC, Mode.AUTOMATIC, targetSize, targetSize);
BufferedImage imageToSave = new BufferedImage(scaledImg.getWidth(), scaledImg.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = imageToSave.getGraphics();
g.drawImage(scaledImg, 0, 0, null);
ImageIO.write(imageToSave, formatName, targetFile);
} finally {
is.close();
}
return EmptySequence.getInstance();
} catch (Exception e) {
throw new XPathException("Error scaling image \"" + source + "\" to \"" + target + "\"", e);
}
}
示例15: paintComponent
import org.imgscalr.Scalr.Mode; //导入依赖的package包/类
/**
* {@inheritDoc}.
*/
@Override
protected synchronized void paintComponent(Graphics g) {
g.setColor(Color.LIGHT_GRAY);
g.fillRect(0, 0, getWidth(), getHeight());
if (image != null)
{
Mode mode = Mode.AUTOMATIC ;
int maxSize = Math.min(this.getWidth(), this.getHeight()) ;
double dh = (double)image.getHeight() ;
if (dh > Double.MIN_VALUE)
{
double imageAspectRatio = (double)image.getWidth() / dh ;
if (this.getHeight() * imageAspectRatio <= this.getWidth())
{
maxSize = this.getHeight() ;
mode = Mode.FIT_TO_HEIGHT ;
}
else
{
maxSize = this.getWidth() ;
mode = Mode.FIT_TO_WIDTH ;
}
}
BufferedImage scaledImg = Scalr.resize(image, Method.AUTOMATIC, mode, maxSize, Scalr.OP_ANTIALIAS) ;
g.drawImage(scaledImg, 0, 0, scaledImg.getWidth(), scaledImg.getHeight(), this);
}
}