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


Java Mode类代码示例

本文整理汇总了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()));
}
 
开发者ID:coding4people,项目名称:mosquito-report-api,代码行数:23,代码来源:PictureBucket.java

示例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();
    }
}
 
开发者ID:lp190zn,项目名称:gTraxxx,代码行数:22,代码来源:ImageResizer.java

示例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) ; 
  }
 
开发者ID:roikku,项目名称:swift-explorer,代码行数:25,代码来源:PdfPanel.java

示例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();
    }
}
 
开发者ID:lp190zn,项目名称:gTraxxx,代码行数:23,代码来源:ImageResizer.java

示例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;
	}
}
 
开发者ID:stasbranger,项目名称:RotaryLive,代码行数:20,代码来源:ImageServiceImpl.java

示例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;
	}
}
 
开发者ID:mnikliborc,项目名称:clicktrace,代码行数:21,代码来源:ScreenShotView.java

示例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);
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:24,代码来源:ImageUtil.java

示例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;
    }
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:26,代码来源:ImageUtil.java

示例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);
}
 
开发者ID:FenixEdu,项目名称:fenixedu-academic,代码行数:17,代码来源:Photograph.java

示例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);
}
 
开发者ID:gentics,项目名称:mesh,代码行数:8,代码来源:ImgscalrImageManipulator.java

示例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);
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:15,代码来源:FocalPointModifier.java

示例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);
    }
}
 
开发者ID:grro,项目名称:reactivecassandra,代码行数:14,代码来源:HotelService.java

示例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);
}
 
开发者ID:alex-bretet,项目名称:cloudstreetmarket.com,代码行数:11,代码来源:ImageUtil.java

示例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);
  }
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:46,代码来源:Scale.java

示例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);
    }
}
 
开发者ID:roikku,项目名称:swift-explorer,代码行数:31,代码来源:ImagePanel.java


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