当前位置:网站首页>Processing picture class library
Processing picture class library
2022-06-25 09:38:00 【String-int】
POM.XML
<!-- https://mvnrepository.com/artifact/net.coobird/thumbnailator -->
<!-- Processing picture class library -->
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.14</version>
</dependency>
JAVA
package com.example.demo;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;
import net.coobird.thumbnailator.name.Rename;
import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class TestImg {
public static void main(String[] args) throws IOException {
//size( Width , Height )
/* * If the horizontal ratio of the picture 200 Small , High ratio 300 Small , unchanged * If the horizontal ratio of the picture 200 Small , High ratio 300 Big , The height is reduced to 300, The scale of the picture is the same * If the horizontal ratio of the picture 200 Big , High ratio 300 Small , Horizontal reduction to 200, The scale of the picture is the same * If the horizontal ratio of the picture 200 Big , High ratio 300 Big , The picture is scaled down , Horizontal 200 Or as high as 300 */
// Scene application
/** *1. Specify the size to zoom */
Thumbnails.of("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg")
.size(200, 300)
.toFile("C:\\Users\\Administrator\\Desktop\\tu/junma.jpg");
// Thumbnails.of("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/0.1.jpeg")
// .size(2560, 2048)
// .toFile("C:\\Users\\Administrator\\Desktop\\tu/0.1.jpeg");
/** * 2. Single picture is scaled equally */
// File file = new File("D:\\\\project\\\\suining\\\\processingimgs\\\\src\\\\main\\\\resources\\\\static\\\\images/0.2.jpg");
// // 3.0 It's a double Type of number , Zoom ratio , Greater than 1 Just get bigger , Less than 1 Is to shrink
// Thumbnails.of(new FileInputStream(file)).scale(0.1).toFile(new File("C:\\\\Users\\\\Administrator\\\\Desktop\\\\tu/0.2.jpg"));
/** * 3. Not in proportion , Specify the size to zoom */
//keepAspectRatio(false) The default is true Scaled ,false Do not scale
// Thumbnails.of("D:\\\\project\\\\suining\\\\processingimgs\\\\src\\\\main\\\\resources\\\\static\\\\images/0.4.jpeg")
// .size(200, 300)
// .keepAspectRatio(false)
// .toFile("C:\\\\\\\\Users\\\\\\\\Administrator\\\\\\\\Desktop\\\\\\\\tu/0.4.jpg");
/** * 4. Generate thumbnails in batch */
//C:\Users\Administrator\Desktop\tu Is the folder to generate thumbnails , The pictures in the folder will be generated into thumbnails ,png It's the format of the picture
Thumbnails.of(new File("C:\\Users\\Administrator\\Desktop\\tu").listFiles()).scale(0.2).outputFormat("jpg")
.toFiles(Rename.PREFIX_DOT_THUMBNAIL);
/** * 5. Picture quality control , The picture size remains the same */
// File fromPic =new File("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/0.5.jpeg");
// File toPic =new File("C:\\Users\\Administrator\\Desktop\\tu/0.5.jpeg");
// //outputQuality It is used to control the image quality
// Thumbnails.of(fromPic).scale(1f).outputQuality(0.25f).toFile(toPic);
//
/** * * failed !!!!!! * 6. Watermark the picture * fromPic It's the original picture ,waterPic Is a watermark image ,toPic Is the generated picture */
// File fromPic =new File("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg");
// File waterPic =new File("C:\\Users\\Administrator\\Desktop\\tu/thumbnail.0.4.jpg.png");
// File toPic =new File("C:\\Users\\Administrator\\Desktop\\tu/haha.jpg");
// Thumbnails.of(fromPic).scale(0.8)
// .watermark(Positions.BOTTOM_RIGHT, ImageIO.read(waterPic), 0.5f)
// .outputQuality(0.8f).toFile(toPic);
//
watermark( Location , Watermark , transparency )
// Thumbnails.of("images/a380_1280x1024.jpg")
// .size(1280, 1024)
// .watermark(Positions.BOTTOM_RIGHT, ImageIO.read(new File("images/watermark.png")), 0.5f)
// .outputQuality(0.8f)
// .toFile("c:/a380_watermark_bottom_right.jpg");
//
// Thumbnails.of("images/a380_1280x1024.jpg")
// .size(1280, 1024)
// .watermark(Positions.CENTER, ImageIO.read(new File("images/watermark.png")), 0.5f)
// .outputQuality(0.8f)
// .toFile("c:/a380_watermark_center.jpg");
/** * 7. Rotate the picture */
// File fromPic =new File("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg");
// File toPic =new File("C:\\Users\\Administrator\\Desktop\\tu/thumbnail.0.4.jpg");
// Thumbnails.of(fromPic).scale(0.5).rotate(90).toFile(toPic);
/** * Image clipping */
// File fromPic =new File("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg");
// File toPic =new File("C:\\Users\\Administrator\\Desktop\\tu/thumbnail.0.4.jpg");
// Thumbnails.of(fromPic).sourceRegion(Positions.CENTER, 300, 300).scale(1.0).toFile(toPic);
//
// //sourceRegion()
//
// // Picture center 400*400 Region
// Thumbnails.of("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg")
// .sourceRegion(Positions.CENTER, 400,400)
// .size(200, 200)
// .keepAspectRatio(false)
// .toFile("C:\\Users\\Administrator\\Desktop\\tu/a380_region_center.jpg");
//
// // Bottom right of the picture 400*400 Region
// Thumbnails.of("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg")
// .sourceRegion(Positions.BOTTOM_RIGHT, 400,400)
// .size(200, 200)
// .keepAspectRatio(false)
// .toFile("C:\\Users\\Administrator\\Desktop\\tu/a380_region_bootom_right.jpg");
//
// // Specify coordinates
// Thumbnails.of("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/junma.jpg")
// .sourceRegion(600, 500, 400, 400)
// .size(200, 200)
// .keepAspectRatio(false)
// .toFile("C:\\Users\\Administrator\\Desktop\\tu/a380_region_coord.jpg");
// Images uploaded by some apps may be of high quality , But when users browse the list , I don't want to show the original picture , Because the bandwidth requirements are high ,
// This can reduce the picture quality ( As mentioned above outputQuality), With outputstream The way of output stream response Show the browser
// narrow scale(0.5)、 quality outputQuality(0.1)
// narrow 0.5, quality 0.1, The output image size is only 6.2KB 了 , Greatly accelerated web The speed of browsing pictures
}
}
package com.example.demo;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.name.Rename;
import java.io.File;
import java.io.IOException;
public class ThumbnailatorTest {
public static void main(String[] args) throws IOException {
// File directory=new File("C:\\Users\\Administrator\\Desktop\\tu");
// Thumbnails.of(directory.listFiles())
// .size(200, 200)
// .outputFormat("jpeg")
// .asFiles(Rename.PREFIX_DOT_THUMBNAIL);
Thumbnails.of(new File("C:\\Users\\Administrator\\Desktop\\tu").listFiles())
.size(300, 200).keepAspectRatio(false).outputFormat("jpg")
.toFiles(Rename.PREFIX_DOT_THUMBNAIL);
}
}
package com.example.demo;
import com.sun.istack.internal.logging.Logger;
import jdk.management.resource.internal.inst.InitInstrumentation;
import net.coobird.thumbnailator.Thumbnailator;
import net.coobird.thumbnailator.Thumbnails;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
@RestController
public class TestController {
@RequestMapping("test")
public void getImg(HttpServletRequest request, HttpServletResponse response) throws IOException {
Thumbnails.of(new File("D:\\project\\suining\\processingimgs\\src\\main\\resources\\static\\images/0.1.jpeg"))
.size(300,200).outputFormat("jpg").toOutputStream(response.getOutputStream());
}
}
边栏推荐
- Voiceprint Technology (V): voiceprint segmentation and clustering technology
- [IOU] intersection over union
- Is it safe to open an account on the compass?
- 瑞吉外卖项目(二)
- 首期Techo Day腾讯技术开放日,628等你!
- 从海量手机号中匹配某一个手机号
- 22 mathematical modeling contest 22 contest C
- Opencv中的GrabCut图像分割
- [2020 cloud development + source code] 30 minutes to create and launch wechat applet practical project | zero cost | cloud database | cloud function
- Socket programming -- poll model
猜你喜欢

TLAB mechanism of JVM object memory allocation and TLAB process in G1
![[design completion - opening report] zufeinfo 2018 software engineering major (including FAQ)](/img/b7/fb7ead787e00047f3663e8b5acfe33.jpg)
[design completion - opening report] zufeinfo 2018 software engineering major (including FAQ)

203 postgraduate entrance examination Japanese self-study postgraduate entrance examination experience post; Can I learn Japanese by myself?

Matplotlib plt grid()
![[IOU] intersection over union](/img/17/a3e2144dfbd9248034cae285ee85bd.jpg)
[IOU] intersection over union

《JVM》对象内存分配的TLAB机制与G1中的TLAB流程

22 mathematical modeling contest 22 contest C
![[MySQL learning notes 21] storage engine](/img/3a/a3cd573281efc689cafdb7d7562ce0.png)
[MySQL learning notes 21] storage engine

Data-driven anomaly detection and early warning of item C in the May 1st mathematical modeling competition in 2021

Benefits and types of cloud network technology
随机推荐
首期Techo Day腾讯技术开放日,628等你!
oracle 函数 触发器
如何自制一个安装程序,将程序打包生成安装程序的办法
Socket programming -- poll model
How to delete a blank page that cannot be deleted in word
Is the security account opening risky and safe?
Oracle function trigger
Pytorch_Geometric(PyG)使用DataLoader报错RuntimeError: Sizes of tensors must match except in dimension 0.
Voiceprint Technology (III): voiceprint recognition technology
Voiceprint Technology (V): voiceprint segmentation and clustering technology
[final review notes] digital logic
Atguigu---18-component
[shared farm] smart agriculture applet, customized development and secondary development of Kaiyuan source code, which is more appropriate?
[matlab] image binarization (imbinarize function)
Nano data World Cup data interface, CSL data, sports data score, world cup schedule API, real-time data interface of football match
Study on correlation of pumpkin price and design of price prediction model based on BP neural network
[wechat applet full stack development course] course directory (mpvue+koa2+mysql)
Fcpx quickly add subtitles | Final Cut Pro import fcpxml subtitle file does not match the video time? I got it in code
How much money have I made by sticking to fixed investment for 3 years?
Voiceprint Technology (VI): other applications of voiceprint Technology