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


Java Scalr.resize方法代码示例

本文整理汇总了Java中org.imgscalr.Scalr.resize方法的典型用法代码示例。如果您正苦于以下问题:Java Scalr.resize方法的具体用法?Java Scalr.resize怎么用?Java Scalr.resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.imgscalr.Scalr的用法示例。


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

示例1: uploadThumbnail

import org.imgscalr.Scalr; //导入方法依赖的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; //导入方法依赖的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: resizeJpgToFile

import org.imgscalr.Scalr; //导入方法依赖的package包/类
@BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 1, concurrency = 1)
@Test
// round: 0.07 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+-
// 0.00], GC.calls: 0, GC.time: 0.00, time.total: 0.36, time.warmup: 0.29,
// time.bench: 0.07
public void resizeJpgToFile() throws Exception {
	BufferedImage srcImage = ImageIO.read(new File(
			"custom/input/image/Tulips.jpg"));
	int resizeWidth = (int) (srcImage.getWidth() * 0.8);
	int resizeHeight = (int) (srcImage.getHeight() * 0.8);

	BufferedImage destImage = Scalr.resize(srcImage,
			Scalr.Method.AUTOMATIC, resizeWidth, resizeHeight);

	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	ImageIO.write(destImage, "jpg", bos);

	// save to file
	FileUtils.writeByteArrayToFile(new File(
			"custom/input/image/Tulips-resize-80-imgscalr.jpg"), bos
			.toByteArray());
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:23,代码来源:BenchmarkImgscalrTest.java

示例4: resizeImage

import org.imgscalr.Scalr; //导入方法依赖的package包/类
@Override
public void resizeImage(byte[] bytes, String dirStr, String fileName, int targetSize) throws Exception {
	BufferedImage orginalImage = ImageIO.read(new ByteArrayInputStream(bytes));
	
	String[] splt = splitFileName(fileName);
	String randomFileName = splt[0];
	String fileExtension = splt[1];
	
	String savedImageName = targetSize + "-" + randomFileName + "." + fileExtension;
	String uploadPath = dirStr + SEPARATOR + savedImageName;
	
	BufferedImage scaledImage = Scalr.resize(orginalImage, targetSize);
	ByteArrayOutputStream os = new ByteArrayOutputStream();
	ImageIO.write(scaledImage, fileExtension, os);
	InputStream is = new ByteArrayInputStream(os.toByteArray());
	
	dropBoxSave(uploadPath, is);
	
}
 
开发者ID:quebic-source,项目名称:microservices-sample-project,代码行数:20,代码来源:DropBoxStorageImageUtil.java

示例5: resizeImagesWithTempThubnails

import org.imgscalr.Scalr; //导入方法依赖的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

示例6: createThumbnails

import org.imgscalr.Scalr; //导入方法依赖的package包/类
/**
 * Creates the thumbnails for photos with a size of 200*200.
 *
 * @param offer the offer
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void createThumbnails(Offer offer) throws IOException{
	
	for(OfferPhoto photo : offer.getOfferPhotos()) {
		if(photo.getThumbnail() == null) {
			InputStream inputStream = new ByteArrayInputStream(photo.getPhoto());
			
			BufferedImage img = ImageIO.read(inputStream);
			BufferedImage thumbNail = Scalr.resize(img, 200);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			ImageIO.write(thumbNail,photo.getImageFormat() , baos);
			photo.setThumbnail(baos.toByteArray());
			inputStream.close();
			baos.close();	
		}
	}
}
 
开发者ID:andju,项目名称:findlunch,代码行数:23,代码来源:OfferDetailController.java

示例7: handleFileUpload

import org.imgscalr.Scalr; //导入方法依赖的package包/类
@RequestMapping(value = "/user/upload", method = RequestMethod.POST)
public String handleFileUpload(@RequestParam("file") MultipartFile file) {
	Format formatter = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss");
	String fileName = formatter.format(Calendar.getInstance().getTime()) + "_thumbnail.jpg";
	User user = userService.getLoggedInUser();
	if (!file.isEmpty()) {
		try {
			String saveDirectory = userRoot + File.separator + user.getId() + File.separator;
			File test = new File(saveDirectory);
			if (!test.exists())
				test.mkdirs();
			byte[] bytes = file.getBytes();
			ByteArrayInputStream imageInputStream = new ByteArrayInputStream(bytes);
			BufferedImage image = ImageIO.read(imageInputStream);
			BufferedImage thumbnail = Scalr.resize(image, 200);
			File thumbnailOut = new File(saveDirectory + fileName);
			ImageIO.write(thumbnail, "png", thumbnailOut);
			userService.updateProfilePicture(user, fileName);
			userService.getLoggedInUser(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return "redirect:/user/edit";
}
 
开发者ID:marcin-pwr,项目名称:hotel,代码行数:26,代码来源:UserController.java

示例8: getSmallApplicationIcon

import org.imgscalr.Scalr; //导入方法依赖的package包/类
protected static Icon getSmallApplicationIcon() {
  if (ourSmallAppIcon == null) {
    try {
      Icon appIcon = IconLoader.findIcon(ApplicationInfoEx.getInstanceEx().getIconUrl());

      if (appIcon != null) {
        if (appIcon.getIconWidth() == JBUI.scale(16) && appIcon.getIconHeight() == JBUI.scale(16)) {
          ourSmallAppIcon = appIcon;
        } else {
          BufferedImage image = ImageUtil.toBufferedImage(IconUtil.toImage(appIcon));
          image = Scalr.resize(image, Scalr.Method.ULTRA_QUALITY, UIUtil.isRetina() ? 32 : JBUI.scale(16));
          ourSmallAppIcon = toRetinaAwareIcon(image);
        }
      }
    }
    catch (Exception e) {//
    }
    if (ourSmallAppIcon == null) {
      ourSmallAppIcon = EmptyIcon.ICON_16;
    }
  }

  return ourSmallAppIcon;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:RecentProjectsManagerBase.java

示例9: getScaledIcon

import org.imgscalr.Scalr; //导入方法依赖的package包/类
private ImageIcon getScaledIcon(ImageIcon original) {
  Canvas c = new Canvas();
  FontMetrics fm = c.getFontMetrics(new JPanel().getFont());

  int height = (int) (fm.getHeight() * 2f);
  int width = original.getIconWidth() / original.getIconHeight() * height;

  BufferedImage scaledImage;
  if (!scraper.isEnabled()) {
    scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
        Scalr.OP_GRAYSCALE);
  }
  else {
    scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
        Scalr.OP_ANTIALIAS);
  }
  return new ImageIcon(scaledImage);
}
 
开发者ID:tinyMediaManager,项目名称:tinyMediaManager,代码行数:19,代码来源:TvShowScraperSettingsPanel.java

示例10: resizePng

import org.imgscalr.Scalr; //导入方法依赖的package包/类
@BenchmarkOptions(benchmarkRounds = 100, warmupRounds = 1, concurrency = 100)
@Test
// round: 3.64 [+- 1.11], round.block: 0.00 [+- 0.01], round.gc: 0.00 [+-
// 0.00], GC.calls: 9, GC.time: 0.10, time.total: 5.37, time.warmup: 0.00,
// time.bench: 5.37
public void resizePng() throws Exception {
	BufferedImage srcImage = ImageIO.read(new File(
			"custom/input/image/Tulips.png"));
	int resizeWidth = (int) (srcImage.getWidth() * 0.8);
	int resizeHeight = (int) (srcImage.getHeight() * 0.8);

	BufferedImage destImage = Scalr.resize(srcImage,
			Scalr.Method.AUTOMATIC, resizeWidth, resizeHeight);

	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	ImageIO.write(destImage, "png", bos);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:18,代码来源:BenchmarkImgscalrTest.java

示例11: scaleByHeight

import org.imgscalr.Scalr; //导入方法依赖的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

示例12: testResizeSmallJpegImage

import org.imgscalr.Scalr; //导入方法依赖的package包/类
public void testResizeSmallJpegImage() throws Exception
{
	final int size = 36;
	File source = new File("./src/test/java/org/benetech/secureapp/generator/smallImage.jpg");
	assertTrue("small image not found?", source.exists());
	BufferedImage bufferedImage = ImageIO.read(source);
	BufferedImage scaledImg = Scalr.resize(bufferedImage, Scalr.Mode.AUTOMATIC, size, size);
	assertEquals("Original image height incorrect?", 22, bufferedImage.getHeight());
	assertEquals("Original image width incorrect?", 22, bufferedImage.getWidth());
	assertEquals("Image height not scaled up?", 36, scaledImg.getHeight());
	assertEquals("Image width not scaled up?", 36, scaledImg.getWidth());
	File destination = File.createTempFile("testSmallImage", ".png");
	destination.deleteOnExit();
	ImageIO.write(scaledImg, "png", destination);
	assertTrue("File not saved as png?", destination.exists());
	BufferedImage retrievedImage = ImageIO.read(destination);
	assertEquals("retrieved Image height not scaled up?", 36, retrievedImage.getHeight());
	assertEquals("retrieved Image width not scaled up?", 36, retrievedImage.getWidth());
}
 
开发者ID:benetech,项目名称:Secure-App-Generator,代码行数:20,代码来源:TestImageResize.java

示例13: createThumbnail

import org.imgscalr.Scalr; //导入方法依赖的package包/类
/**
 * creates the Thumbnail for the given picture and stores it on the disk
 * 
 * @param image
 */
public static void createThumbnail(File image, int size, File dest) throws IOException {
    BufferedImage thumbnail = ImageIO.read(image);
    int width = thumbnail.getWidth();
    int height = thumbnail.getHeight();
    if (width > size || height > size) {
        if (width > height) {
            thumbnail = Scalr.resize(thumbnail, Scalr.Mode.FIT_TO_HEIGHT, size);
            thumbnail = Scalr.crop(thumbnail, thumbnail.getWidth() / 2 - size / 2, 0, size, size);
        } else {
            thumbnail = Scalr.resize(thumbnail, Scalr.Mode.FIT_TO_WIDTH, size);
            thumbnail = Scalr.crop(thumbnail, 0, thumbnail.getWidth() / 2 - size / 2, size, size);
        }
    }
    String suffix;
    if (image.getName().lastIndexOf(".") != -1) {
    	suffix = image.getName().substring(image.getName().lastIndexOf(".") + 1);
    } else {
    	suffix = "png";//by default.
    }
       ImageIO.write(thumbnail, suffix, dest);
}
 
开发者ID:shaolinwu,项目名称:uimaster,代码行数:27,代码来源:ImageUtil.java

示例14: doInBackground

import org.imgscalr.Scalr; //导入方法依赖的package包/类
@Override
protected BufferedImage doInBackground() throws Exception {
  Path file = null;

  if (useCache) {
    file = ImageCache.getCachedFile(Paths.get(imagePath));
  }

  if (file == null) {
    file = Paths.get(imagePath);
  }

  if (file != null && Files.exists(file)) {
    try {
      return Scalr.resize(ImageCache.createImage(file), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, newSize.width, newSize.height,
          Scalr.OP_ANTIALIAS);
    }
    catch (Exception e) {
      return null;
    }
  }
  else {
    return null;
  }
}
 
开发者ID:tinyMediaManager,项目名称:tinyMediaManager,代码行数:26,代码来源:ImageLabel.java

示例15: resizeNormalImage

import org.imgscalr.Scalr; //导入方法依赖的package包/类
private static BufferedImage resizeNormalImage(BufferedImage image,
                                               int newWidth,
                                               int newHeight,
                                               ImageInformation information) throws IOException {
    if (newWidth == information.getImageWidth() &&
        newHeight == information.getImageHeight() &&
        MathUtils.floatEquals(information.getFactor(), 1f)) {
        return image;
    }
    BufferedImage resizedImage = null;
    switch (information.getAlgorithm()) {
        case SCALR:
            Scalr.Method scalrMethod = (Scalr.Method) information.getMethod();
            resizedImage = Scalr.resize(image, scalrMethod, newWidth, newHeight, Scalr.OP_ANTIALIAS);
            break;
        case THUMBNAILATOR:
            return Thumbnails.of(image)
                             .size(newWidth, newHeight)
                             .asBufferedImage();
    }
    return resizedImage;
}
 
开发者ID:sayedyousef,项目名称:plgin,代码行数:23,代码来源:ImageUtils.java


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