本文整理了Java中net.coobird.thumbnailator.Thumbnails.of()
方法的一些代码示例,展示了Thumbnails.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thumbnails.of()
方法的具体详情如下:
包路径:net.coobird.thumbnailator.Thumbnails
类名称:Thumbnails
方法名:of
[英]Indicate to make thumbnails from the specified BufferedImages.
[中]指示从指定的BuffereImage生成缩略图。
代码示例来源:origin: coobird/thumbnailator
Thumbnails.of(inFile)
.size(width, height)
.toFile(outFile);
代码示例来源:origin: coobird/thumbnailator
/**
* Creates a thumbnail from an image file, and returns as a
* {@link BufferedImage}.
*
* @param f The {@link File} from which image data is read.
* @param width The width of the thumbnail.
* @param height The height of the thumbnail.
* @return The thumbnail image as a {@link BufferedImage}.
* @throws IOException Thrown when a problem occurs when reading from
* {@code File} representing an image file.
*/
public static BufferedImage createThumbnail(
File f,
int width,
int height
) throws IOException
{
validateDimensions(width, height);
if (f == null)
{
throw new NullPointerException("Input file is null.");
}
return Thumbnails.of(f).size(width, height).asBufferedImage();
}
代码示例来源:origin: coobird/thumbnailator
Thumbnails.of(is)
.size(width, height)
.outputFormat(format)
代码示例来源:origin: sanluan/PublicCMS
public void thumb(String sourceFilePath, String thumbFilePath, Integer width, Integer height) throws IOException {
try (FileOutputStream outputStream = new FileOutputStream(thumbFilePath);) {
Thumbnails.of(sourceFilePath).size(width, height).toOutputStream(outputStream);
}
}
代码示例来源:origin: sanluan/PublicCMS
public void thumb(String sourceFilePath, String thumbFilePath, Integer width, Integer height) throws IOException {
try (FileOutputStream outputStream = new FileOutputStream(thumbFilePath);) {
Thumbnails.of(sourceFilePath).size(width, height).toOutputStream(outputStream);
}
}
代码示例来源:origin: winterDroid/android-drawable-importer-intellij-plugin
private static BufferedImage resizeNormalImage(BufferedImage image,
ImageInformation information) throws IOException {
int newWidth = image.getWidth();
int newHeight = image.getHeight();
if (MathUtils.floatEquals(information.getFactor(), 1f)) {
return image;
}
if (information.getFactor() >= 0) {
newWidth = (int) (newWidth * information.getFactor());
newHeight = (int) (newHeight * information.getFactor());
}
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;
}
代码示例来源:origin: jmrozanec/pdf-converter
private void persistImage(BufferedImage image, int width, int height, File output) throws IOException {
System.out.println(output);
output.getParentFile().mkdirs();
ImageIO.write(Thumbnails.of(image).size(width, height).asBufferedImage(), FilenameUtils.getExtension(output.getAbsolutePath()), output);
}
}
代码示例来源:origin: youngMen1/JAVA-
/**
* 根据比例缩放图片
*
* @param orgImgFile 源图片路径
* @param scale 比例
* @param targetFile 缩放后的图片存放路径
* @throws IOException
*/
public static final void scale(BufferedImage orgImg, double scale, String targetFile) throws IOException {
Thumbnails.of(orgImg).scale(scale).toFile(targetFile);
}
代码示例来源:origin: patrickfav/uber-adb-tools
private static File downscaleIfNeeded(File localTempFile, Arg arg) {
if (localTempFile.exists() && localTempFile.isFile() && FileUtil.getFileExtension(localTempFile).equalsIgnoreCase("png") && localTempFile.length() > MAX_IMG_BYTE_SIZE) {
try {
while (localTempFile.length() > MAX_IMG_BYTE_SIZE) {
Thumbnails.of(localTempFile).allowOverwrite(true).scale(0.5).toFile(localTempFile);
}
Commons.log("\tdownscaling screenshot", arg);
} catch (IOException e) {
throw new IllegalStateException("could not resize screenshot", e);
}
}
return localTempFile;
}
代码示例来源:origin: tobato/FastDFS_Client
/**
* 根据传入比例生成缩略图
*
* @param inputStream
* @param thumbImage
* @return
* @throws IOException
*/
private ByteArrayInputStream generateThumbImageByPercent(InputStream inputStream,
ThumbImage thumbImage) throws IOException {
LOGGER.debug("根据传入比例生成缩略图");
// 在内存当中生成缩略图
ByteArrayOutputStream out = new ByteArrayOutputStream();
//@formatter:off
Thumbnails
.of(inputStream)
.scale(thumbImage.getPercent())
.toOutputStream(out);
//@formatter:on
return new ByteArrayInputStream(out.toByteArray());
}
代码示例来源:origin: 94fzb/zrlog
public static byte[] jpeg(byte[] buf, float quality) throws IOException {
ByteArrayInputStream bain = new ByteArrayInputStream(buf);
ByteArrayOutputStream baout = new ByteArrayOutputStream();
Thumbnails.of(bain).outputQuality(quality).rendering(Rendering.SPEED).width(660).toOutputStream(baout);
return baout.toByteArray();
}
}
代码示例来源:origin: youngMen1/JAVA-
public static final void scale(String orgImgFile, double scale, String targetFile) throws IOException {
Thumbnails.of(orgImgFile).scale(scale).toFile(targetFile);
}
代码示例来源:origin: youngMen1/JAVA-
/**
* * 转换图片大小,不变形
*
* @param img 图片文件
* @param width 图片宽
* @param height 图片高
*/
public static final void changeImge(File img, int width, int height) {
try {
Thumbnails.of(img).size(width, height).keepAspectRatio(false).toFile(img);
} catch (IOException e) {
e.printStackTrace();
throw new IllegalStateException("图片转换出错!", e);
}
}
代码示例来源:origin: Cool-Coding/remote-desktop-control
/**
* 字节数组转化为图像
* @param data
* 字节数组
* @return
* 图像
*/
public static BufferedImage getImageFromByteArray(byte[] data){
try {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data);
return Thumbnails.of(byteArrayInputStream).scale(1f).outputFormat("jpg").asBufferedImage();
}catch (IOException e){
throw new RuntimeException(e);
}
}
代码示例来源:origin: tobato/FastDFS_Client
/**
* 获取缩略图
*
* @param inputStream
* @return
* @throws IOException
*/
private ByteArrayInputStream generateThumbImageByDefault(InputStream inputStream) throws IOException {
LOGGER.debug("根据默认配置生成缩略图");
// 在内存当中生成缩略图
ByteArrayOutputStream out = new ByteArrayOutputStream();
//@formatter:off
Thumbnails
.of(inputStream)
.size(thumbImageConfig.getWidth(), thumbImageConfig.getHeight())
.toOutputStream(out);
//@formatter:on
return new ByteArrayInputStream(out.toByteArray());
}
代码示例来源:origin: landy8530/netty-file-parent
/**
* 利用Thumbnailator生成缩略图
*
* @author liuyuanxian
*/
public void createThumbImage() {
//asBufferedImage() 返回BufferedImage
try {
BufferedImage thumbnail = Thumbnails.of(inPutFile)
.size(width, height).keepAspectRatio(proportion)
.asBufferedImage();
ImageIO.write(thumbnail, "jpg", outPutFile);
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: Cool-Coding/remote-desktop-control
/**
* 保持宽高比压缩图像
* @param image
* 图像
* @param quality
* 质量(0,1]
* @return
* 压缩后的图像
*/
public static BufferedImage compressedImage(BufferedImage image, float quality) {
try {
return Thumbnails.of(image).scale(1f).outputQuality(quality).asBufferedImage();
}catch (IOException e){
throw new RuntimeException(e);
}
}
代码示例来源:origin: youngMen1/JAVA-
/**
* 图片格式转换
*
* @param orgImgFile
* @param width
* @param height
* @param suffixName
* @param targetFile
* @throws IOException
*/
public static final void format(String orgImgFile, int width, int height, String suffixName, String targetFile)
throws IOException {
Thumbnails.of(orgImgFile).size(width, height).outputFormat(suffixName).toFile(targetFile);
}
代码示例来源:origin: io.github.aktoluna/slnarch-common
public static File resizeWithThumbnails(File file, int width, int height) throws IOException {
File outputFile = new File(getOutputFilePath(file));
Thumbnails.of(file)
.size(width, height)
.outputFormat("jpg")
.outputQuality(0.5f)
.toFile(outputFile);
return outputFile;
}
代码示例来源:origin: CognitiveJ/cognitivej
public static BufferedImage loadAndNameCandidateImages(ImageHolder imageHolder) {
try {
BufferedImage thumbnail = Thumbnails.of(new URL((String) imageHolder.firstImage().getImage()))
.crop(Positions.CENTER).size(200, 200).asBufferedImage();
ApplyCaptionOutsideImageFilter applyCaptionOutsideImageFilter = new ApplyCaptionOutsideImageFilter(PointLocations.BOTTOM_CENTER,
ImageOverlayBuilder.DEFAULT_TEXT_FONT, CognitiveJColourPalette.WHITE, imageHolder.getName());
return applyCaptionOutsideImageFilter.applyFilter(thumbnail);
} catch (IOException e) {
throw new CognitiveException("Could not make thumbnail", e);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!