本文整理汇总了Java中org.imgscalr.Scalr类的典型用法代码示例。如果您正苦于以下问题:Java Scalr类的具体用法?Java Scalr怎么用?Java Scalr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Scalr类属于org.imgscalr包,在下文中一共展示了Scalr类的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()));
}
示例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();
}
}
示例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());
}
示例4: getBestFit
import org.imgscalr.Scalr; //导入依赖的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) ;
}
示例5: 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);
}
示例6: 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();
}
}
示例7: 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();
}
}
}
示例8: onViewInit
import org.imgscalr.Scalr; //导入依赖的package包/类
@Override
public void onViewInit() {
this.setLayout(new GridLayout(1, 1));
this.setPreferredSize(this.descriptor.getSize());
this.captureLabel = new JLabel();
this.setBackground(AppThemeColor.ADR_CAPTURE_BG);
this.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER, 1));
this.progressTl = new Timeline(this);
this.progressTl.addPropertyToInterpolate("captureCount", 0, this.descriptor.getFps());
this.captureLabel.setIcon(new ImageIcon(Scalr.resize(getCapture(), descriptor.getSize().width, descriptor.getSize().height)));
this.progressTl.addCallback(new TimelineCallbackAdapter() {
@Override
public void onTimelineStateChanged(Timeline.TimelineState oldState, Timeline.TimelineState newState, float durationFraction, float timelinePosition) {
captureLabel.setIcon(new ImageIcon(Scalr.resize(getCapture(), descriptor.getSize().width, descriptor.getSize().height)));
}
});
this.progressTl.setDuration(1000 / this.descriptor.getFps());
this.add(this.captureLabel);
MercuryStoreUI.adrRepaintSubject.onNext(true);
}
示例9: 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";
}
示例10: getThumbnail
import org.imgscalr.Scalr; //导入依赖的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;
}
}
示例11: 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;
}
示例12: scale
import org.imgscalr.Scalr; //导入依赖的package包/类
@Override
public Icon scale(float scaleFactor) {
if (scaleFactor == 1f) {
return this;
}
if (scaledIcons == null) {
scaledIcons = new HashMap<Float, Icon>(1);
}
Icon result = scaledIcons.get(scaleFactor);
if (result != null) {
return result;
}
final Image image = ImageUtil.filter(ImageLoader.loadFromUrl(myUrl, UIUtil.isUnderDarcula(), scaleFactor >= 1.5f), filter);
if (image != null) {
int width = (int)(getIconWidth() * scaleFactor);
int height = (int)(getIconHeight() * scaleFactor);
final BufferedImage resizedImage = Scalr.resize(ImageUtil.toBufferedImage(image), Scalr.Method.ULTRA_QUALITY, width, height);
result = getIcon(resizedImage);
scaledIcons.put(scaleFactor, result);
return result;
}
return this;
}
示例13: testResizeLargePngImage
import org.imgscalr.Scalr; //导入依赖的package包/类
public void testResizeLargePngImage() throws Exception
{
final int size = 36;
File source = new File("./src/test/java/org/benetech/secureapp/generator/largeImage.png");
assertTrue("large 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?", 587, bufferedImage.getHeight());
assertEquals("Original image width incorrect?", 303, bufferedImage.getWidth());
assertEquals("Image height not scaled down?", 36, scaledImg.getHeight());
assertEquals("Image width not scaled down?", 19, scaledImg.getWidth());
File destination = File.createTempFile("testLargeImage", ".png");
destination.deleteOnExit();
ImageIO.write(scaledImg, "png", destination);
assertTrue("File not saved?", destination.exists());
BufferedImage retrievedImage = ImageIO.read(destination);
assertEquals("retrieved Image height not scaled down?", 36, retrievedImage.getHeight());
assertEquals("retrieved Image width not scaled down?", 19, retrievedImage.getWidth());
}
示例14: 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());
}
示例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;
}