当前位置: 首页>>代码示例>>Java>>正文


Java Method类代码示例

本文整理汇总了Java中org.imgscalr.Scalr.Method的典型用法代码示例。如果您正苦于以下问题:Java Method类的具体用法?Java Method怎么用?Java Method使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Method类属于org.imgscalr.Scalr包,在下文中一共展示了Method类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadThumbnail

import org.imgscalr.Scalr.Method; //导入依赖的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()));
}
 
开发者ID:coding4people,项目名称:mosquito-report-api,代码行数:23,代码来源:PictureBucket.java

示例2: getBestFit

import org.imgscalr.Scalr.Method; //导入依赖的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) ; 
  }
 
开发者ID:roikku,项目名称:swift-explorer,代码行数:25,代码来源:PdfPanel.java

示例3: getThumbnail

import org.imgscalr.Scalr.Method; //导入依赖的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;
	}
}
 
开发者ID:stasbranger,项目名称:RotaryLive,代码行数:20,代码来源:ImageServiceImpl.java

示例4: scaleByWidth

import org.imgscalr.Scalr.Method; //导入依赖的package包/类
/**
 * Scales the given image, preserving aspect ratio.
 */
public static BufferedImage scaleByWidth(BufferedImage inImage, int xSize)
{
	double aspectRatio = ((double) inImage.getHeight())
			/ inImage.getWidth();
	int ySize = (int) (xSize * aspectRatio);
	if (ySize == 0)
		ySize = 1;
	
	// This library is described at http://stackoverflow.com/questions/1087236/java-2d-image-resize-ignoring-bicubic-bilinear-interpolation-rendering-hints-os
	BufferedImage scaled = Scalr.resize(inImage, Method.QUALITY, xSize, ySize);

	if (inImage.getType() == BufferedImage.TYPE_BYTE_GRAY && scaled.getType() != BufferedImage.TYPE_BYTE_GRAY)
	{
		scaled = convertToGrayscale(scaled);
	}

	return scaled;
}
 
开发者ID:jeheydorn,项目名称:nortantis,代码行数:22,代码来源:ImageHelper.java

示例5: scaleByHeight

import org.imgscalr.Scalr.Method; //导入依赖的package包/类
/**
 * Scales the given image, preserving aspect ratio.
 */
public static BufferedImage scaleByHeight(BufferedImage inImage, int ySize)
{
	double aspectRatioInverse = ((double) inImage.getWidth())
			/ inImage.getHeight();
	int xSize = (int) (aspectRatioInverse * ySize);
	if (xSize == 0)
		xSize = 1;
	
	// This library is described at http://stackoverflow.com/questions/1087236/java-2d-image-resize-ignoring-bicubic-bilinear-interpolation-rendering-hints-os
	BufferedImage scaled = Scalr.resize(inImage, Method.QUALITY, xSize, ySize);
	
	if (inImage.getType() == BufferedImage.TYPE_BYTE_GRAY && scaled.getType() != BufferedImage.TYPE_BYTE_GRAY)
	{
		scaled = convertToGrayscale(scaled);
	}
	
	return scaled;
}
 
开发者ID:jeheydorn,项目名称:nortantis,代码行数:22,代码来源:ImageHelper.java

示例6: getStyledImage

import org.imgscalr.Scalr.Method; //导入依赖的package包/类
public static BufferedImage getStyledImage(File img, float brightness, float transparency, int size) {
    BufferedImage outputImage = null;
    try {
        BufferedImage readBufferedImage = ImageIO.read(img);
        BufferedImage inputBufferedImage = convertToArgb(readBufferedImage);
        outputImage = inputBufferedImage;
        if (size > 0) {
            outputImage = Scalr.resize(inputBufferedImage
                    , Method.BALANCED
                    , size
                    , size);
        }

        float brightnessFactor = 1.0f + brightness/100.0f;
        float transparencyFactor = Math.abs(transparency/100.0f - 1.0f);
        RescaleOp rescale = new RescaleOp(
                new float[]{brightnessFactor, brightnessFactor, brightnessFactor, transparencyFactor},
                new float[]{0f, 0f, 0f, 0f}, null);
        rescale.filter(outputImage, outputImage);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return outputImage;
}
 
开发者ID:shaolinwu,项目名称:uimaster,代码行数:25,代码来源:ImageUtil.java

示例7: getStyledImage

import org.imgscalr.Scalr.Method; //导入依赖的package包/类
private BufferedImage getStyledImage(float brightness, float transparency, int size) {
    BufferedImage outputImage = null;
    try {
        BufferedImage readBufferedImage = ImageIO.read(new File(imageFilePath));
        BufferedImage inputBufferedImage = convertToArgb(readBufferedImage);
        outputImage = inputBufferedImage;
        if (size > 0) {
            outputImage = Scalr.resize(inputBufferedImage
                    , Method.BALANCED
                    , size
                    , size);
        }

        float brightnessFactor = 1.0f + brightness/100.0f;
        float transparencyFactor = Math.abs(transparency/100.0f - 1.0f);
        RescaleOp rescale = new RescaleOp(
                new float[]{brightnessFactor, brightnessFactor, brightnessFactor, transparencyFactor},
                new float[]{0f, 0f, 0f, 0f}, null);
        rescale.filter(outputImage, outputImage);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return outputImage;
}
 
开发者ID:atominvention,项目名称:AndroidDevToolbox,代码行数:25,代码来源:StatefulButtonController.java

示例8: saveScreenshotThumb

import org.imgscalr.Scalr.Method; //导入依赖的package包/类
/**
 * Save screenshot thumb.
 * 
 * @param screenShotFile
 *            the screen shot file
 * @return the string
 */
private String saveScreenshotThumb(final String screenShotFile) {
    final int thumbWidth = 150;
    final int thumbHeight = 100;
    String screenShotThumb =
            "images" + File.separator + screenShotFile + "_Thumb.png";
    try {
        String screenShotOriginalFile =
                builder.getReportFolderLocation() + File.separator
                        + "images" + File.separator + screenShotFile;
        BufferedImage img = ImageIO.read(new File(screenShotOriginalFile));
        BufferedImage thumb =
                Scalr.resize(img, Method.SPEED, thumbWidth, thumbHeight,
                        Scalr.OP_ANTIALIAS, Scalr.OP_BRIGHTER);

        ImageIO.write(thumb, "png", new File(screenShotOriginalFile
                + "_Thumb.png"));

    } catch (IOException e) {
        e.printStackTrace();
    }
    return screenShotThumb;
}
 
开发者ID:VTAF,项目名称:VirtusaSeleniumWebdriverRuntime,代码行数:30,代码来源:Reporter.java

示例9: checkOptions

import org.imgscalr.Scalr.Method; //导入依赖的package包/类
/**
 * Checks the validity of the options values.
 * @return true if all options have valid values, false otherwise
 */
private boolean checkOptions() {
	String dName = m_nameText.getText();
	if ("".equals(dName)) {
		showError("The default picture start name cannot be empty !");
		return false;
	}
	Method gMethod = m_methodList.getSelectedValue();
	if (gMethod == null) {
		showError("You must select a scaling method to generate the thumbnails !");
		return false;		
	}
	int tSize = (Integer) m_sizeText.getValue();
	if ((tSize < m_minThumbnailSize) || (tSize > m_maxThumbnailSize)) {
		showError("The thumbnail size must be between "+m_minThumbnailSize+ " and "+m_maxThumbnailSize+ " !");
		return false;
	}
	return true;
}
 
开发者ID:geberle,项目名称:PhotMan,代码行数:23,代码来源:PhotManOptionsPane.java

示例10: getListCellRendererComponent

import org.imgscalr.Scalr.Method; //导入依赖的package包/类
@Override
public Component getListCellRendererComponent(JList<? extends Thumb> list, Thumb value, int index, boolean isSelected, boolean cellHasFocus) {
	Thumb entry = (Thumb) value;
	ImageIcon currentIcon = entry.getPreviewImageIconThumbImage();
	//no preview image so let's just try to resize it
	if (currentIcon == null) {
		currentIcon = entry.getImageIconThumbImage();
		//Image scaledImg = currentIcon.getImage().getScaledInstance(250, 250, java.awt.Image.SCALE_SMOOTH);
		BufferedImage img = (BufferedImage) currentIcon.getImage();
		BufferedImage scaledImage = Scalr.resize(img, Method.QUALITY, 250, 250, Scalr.OP_ANTIALIAS);
		currentIcon = new ImageIcon(scaledImage);
	}
	setIcon(currentIcon);
	if (isSelected) {
		setBackground(HIGHLIGHT_COLOR);
		setForeground(Color.white);
	} else {
		setBackground(Color.white);
		setForeground(Color.black);
	}
	return this;
}
 
开发者ID:DoctorD1501,项目名称:JAVMovieScraper,代码行数:23,代码来源:FanartPickerRenderer.java

示例11: imageLoaded

import org.imgscalr.Scalr.Method; //导入依赖的package包/类
@Override
public void imageLoaded(BufferedImage img) {
	//clean up old references, just to be safe
	this.resizedImage = null;
	this.img = null;

	this.img = img;
	if (img != null) {
		isPosterCandidate = (img.getHeight() >= img.getWidth());
		Dimension newImageSize = calculateDimensionFit(img.getWidth(), img.getHeight(), getSize().width, getSize().height);
		this.resizedImage = Scalr.resize(img, Method.QUALITY, Scalr.Mode.AUTOMATIC, newImageSize.width, newImageSize.height, Scalr.OP_ANTIALIAS);

	}
	doneLoading = true;
	repaint();
	handleAutoSelection();
}
 
开发者ID:DoctorD1501,项目名称:JAVMovieScraper,代码行数:18,代码来源:AsyncImageComponent.java

示例12: initializeResourceIcon

import org.imgscalr.Scalr.Method; //导入依赖的package包/类
private static ImageIcon initializeResourceIcon(String resourceName) {
	try {
		URL url = GUIMain.class.getResource(resourceName);
		if (url != null) {
			BufferedImage iconBufferedImage = ImageIO.read(url);
			if (iconBufferedImage != null) {
				iconBufferedImage = Scalr.resize(iconBufferedImage, Method.QUALITY, iconSizeX, iconSizeY, Scalr.OP_ANTIALIAS);
				return new ImageIcon(iconBufferedImage);
			} else
				return new ImageIcon();
		}
		return new ImageIcon();
	} catch (IOException e1) {
		e1.printStackTrace();
		return null;
	}
}
 
开发者ID:DoctorD1501,项目名称:JAVMovieScraper,代码行数:18,代码来源:GUIMainButtonPanel.java

示例13: initializeResourceIcon

import org.imgscalr.Scalr.Method; //导入依赖的package包/类
private ImageIcon initializeResourceIcon(String resourceName, int iconSizeX, int iconSizeY) {
	try {
		URL url = GUIMain.class.getResource(resourceName);
		if (url != null) {
			BufferedImage iconBufferedImage = ImageIO.read(url);
			if (iconBufferedImage != null) {
				iconBufferedImage = Scalr.resize(iconBufferedImage, Method.QUALITY, iconSizeX, iconSizeY, Scalr.OP_ANTIALIAS);
				return new ImageIcon(iconBufferedImage);
			} else
				return new ImageIcon();
		}
		return new ImageIcon();
	} catch (IOException e1) {
		e1.printStackTrace();
		return null;
	}
}
 
开发者ID:DoctorD1501,项目名称:JAVMovieScraper,代码行数:18,代码来源:SiteParsingProfile.java

示例14: scaleImage

import org.imgscalr.Scalr.Method; //导入依赖的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);
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:24,代码来源:ImageUtil.java

示例15: generateImageThumbnail

import org.imgscalr.Scalr.Method; //导入依赖的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;
    }
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:26,代码来源:ImageUtil.java


注:本文中的org.imgscalr.Scalr.Method类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。