java pdf,word,ppt转图片

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.8</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.test</groupId><artifactId>local-service</artifactId><version>0.0.1-SNAPSHOT</version><name>local-service</name><description>local-service</description><properties><java.version>8</java.version><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.13.0</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>2.0.32</version></dependency><!-- https://mvnrepository.com/artifact/org.apache.commons/commons-compress --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-compress</artifactId><version>1.24.0</version></dependency><!--PDF操作工具包--><dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox-app</artifactId><version>2.0.16</version></dependency><!-- word操作工具包--><dependency><groupId>words</groupId><artifactId>aspose-words</artifactId><version>1.0.0</version></dependency><!-- ppt操作工具包--><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-scratchpad</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.xmlgraphics</groupId><artifactId>batik-bridge</artifactId><version>1.9.1</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>
文件转换统一工具类 FileConvertUtil.java

调用 FileConvertUtil.convert2Images(filePath)即可输出图片信息

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.python.jline.internal.Log;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.Base64Utils;import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;/*** @author yangguang* @date 2023年11月01日 17:01*/
@Slf4j
public class FileConvertUtil {private static Map<String, BiFunction<String,String, List<ImageInfo>>> convertFactory = new HashMap<>();static {convertFactory.put("ppt", PPTUtil::ppt2image);convertFactory.put("pptx", PPTUtil::pptx2image);convertFactory.put("doc", WordUtil::word2image);convertFactory.put("docx", WordUtil::word2image);convertFactory.put("pdf", PdfUtil::pdf2image);}public static List<ImageInfo> convert2Images(String filePath) {File file = new File(filePath);String name = file.getName().substring(0,file.getName().lastIndexOf("."));String targetDir = file.getParentFile().getAbsolutePath()+File.separator+name;if(new File(targetDir).exists()){return Arrays.stream(new File(targetDir).listFiles()).map(File::getAbsolutePath).sorted((name1,name2)->Integer.compare(getFileIndex(name1),getFileIndex(name2))).map(FileConvertUtil::file2ImageInfo).collect(Collectors.toList());}else{new File(targetDir).mkdirs();}String suffix = filePath.substring(filePath.lastIndexOf(".") + 1);List<ImageInfo> list = Optional.ofNullable(convertFactory.get(suffix)).map(f -> f.apply(filePath,targetDir)).orElseThrow(() -> new CustomException("不支持得文件类型"));return list;}public static List<String> convert2ImagesBase64(String filePath) {return convert2Images(filePath).stream().map(ImageInfo::getPath).map(FileConvertUtil::base64Encoding).collect(Collectors.toList());}public static void clearWorkPath(File dir) {if (dir == null) {File file = new File(Constants.TEMP_PATH);for (File f : file.listFiles()) {clearWorkPath(f);}} else if (dir.isDirectory()) {for (File file : dir.listFiles()) {clearWorkPath(file);}dir.delete();} else {dir.delete();}}private static String base64Encoding(String imagePath) {InputStream in = null;try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {//建一个空的字节数组byte[] result = null;in = new FileInputStream(imagePath);byte[] buf = new byte[1024];//用来定义一个准备接收图片总长度的局部变量int len;//将流的内容读取到buf内存中while ((len = in.read(buf)) > 0) {//将buf内存中的内容从0开始到总长度输出出去out.write(buf, 0, len);}//将out中的流内容拷贝到一开始定义的字节数组中result = out.toByteArray();//通过util包中的Base64类对字节数组进行base64编码String base64 = Base64.getEncoder().encodeToString(result);return "data:Image/" + "PNG" + ";base64," + base64;} catch (Exception e) {log.error("image to base64 error",e);throw new CustomException("image to base64 error");}}private static int getFileIndex(String filePath){String fileName = new File(filePath).getName();return Integer.parseInt(fileName.substring(0,fileName.lastIndexOf(".")));}private static ImageInfo file2ImageInfo(String filePath) {ImageInfo.ImageInfoBuilder builder = ImageInfo.builder();BufferedImage img = null;File f = null;try {f = new File(filePath);img = ImageIO.read(f);return builder.width(img.getWidth()).height(img.getHeight()).path(filePath).build();}catch (IOException e) {log.error("读取文件失败",e);throw new CustomException("读取文件失败");}}}

图片对象ImageInfo.java

@Data
@Builder
public class ImageInfo {private String path;private Integer width;private Integer height;}
常量文件输出路径Constants.java
/*** @author yangguang* @date 2023年11月01日 15:35*/
public interface Constants {String CONF_PATH = System.getProperty("user.dir") + File.separator + "conf";String TEMP_PATH = System.getProperty("user.dir") + File.separator + "temp";
}

WordUtil.java

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.IntStream;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import com.aspose.words.Document;
import com.aspose.words.ImageSaveOptions;
import com.aspose.words.SaveFormat;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.apache.tomcat.util.http.fileupload.IOUtils;@Slf4j
public class WordUtil {/*** 验证aspose.word组件是否授权:无授权的文件有水印标记* 需要使用(aspose-words-15.8.0-jdk16.jar),版本要对应。无水印* @return*/private static boolean isWordLicense(){boolean result = false;try {String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product></Products><EditionType>Enterprise</EditionType><SubscriptionExpiry>20991231</SubscriptionExpiry><LicenseExpiry>20991231</LicenseExpiry><SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber></Data><Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature></License>";ByteArrayInputStream inputStream = new ByteArrayInputStream(s.getBytes());com.aspose.words.License license = new com.aspose.words.License();license.setLicense(inputStream);result = true;} catch (Exception e) {e.printStackTrace();}return result;}//outputStream转inputStreamprivate static ByteArrayInputStream parse(OutputStream out) throws Exception{ByteArrayOutputStream baos = new ByteArrayOutputStream();baos = (ByteArrayOutputStream) out;ByteArrayInputStream swapStream = new ByteArrayInputStream(baos.toByteArray());return swapStream;}/*** word和txt文件转换图片* @param inputStream* @param* @return* @throws Exception*/private static List<BufferedImage> wordToImg(InputStream inputStream) throws Exception{if (!isWordLicense()){return null;}try {Date start = new Date();Document doc = new Document(inputStream);ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);options.setPrettyFormat(true);options.setUseAntiAliasing(true);options.setUseHighQualityRendering(true);int pageCount = doc.getPageCount();//生成前pageCount张,这可以限制输出长图时的页数(方法入参可以传值pageNum)/*if (pageCount > pageNum) {pageCount = pageNum;}*/List<BufferedImage> imageList = new ArrayList<BufferedImage>();for (int i = 0; i < pageCount; i++){OutputStream output = new ByteArrayOutputStream();options.setPageIndex(i);doc.save(output, options);ImageInputStream imageInputStream = javax.imageio.ImageIO.createImageInputStream(parse(output));imageList.add(javax.imageio.ImageIO.read(imageInputStream));}List<BufferedImage> imageList2 = new ArrayList<BufferedImage>();//这个重新生成新的图片是因为直接输出的图片底色为红色for(int j=0; j<imageList.size(); j++){// 生成新图片BufferedImage destImage = imageList.get(j);int w1 = destImage.getWidth();int h1 = destImage.getHeight();destImage = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB);Graphics2D g2 = (Graphics2D) destImage.getGraphics();g2.setBackground(Color.LIGHT_GRAY);g2.clearRect(0, 0, w1, h1);g2.setPaint(Color.RED);// 从图片中读取RGBint[] ImageArrayOne = new int[w1 * h1];ImageArrayOne = imageList.get(j).getRGB(0, 0, w1, h1, ImageArrayOne, 0, w1); // 逐行扫描图像中各个像素的RGB到数组中destImage.setRGB(0, 0, w1, h1, ImageArrayOne, 0, w1); // 设置上半部分或左半部分的RGBimageList2.add(destImage);}Date end = new Date();long l=end.getTime()-start.getTime();long hour= l / (1000 * 60 * 60);long min=  (l-hour*(1000 * 60 * 60 ))/(1000* 60);long s= (l-hour*(1000 * 60 * 60 )-min*1000*60)/(1000);long ss= (l-hour*(1000 * 60 * 60 )-min*1000*60 -s*1000)/(1000/60);System.out.println("word转图片时间:"+min+"分"+s+"秒" + ss + "毫秒");//hour+"小时"+return imageList2;} catch (Exception e) {e.printStackTrace();throw e;}}/*** 合并任数量的图片成一张图片* @param isHorizontal true代表水平合并,fasle代表垂直合并* @param imgs 待合并的图片数组* @return* @throws IOException*/public static BufferedImage mergeImage(boolean isHorizontal, List<BufferedImage> imgs) throws IOException{// 生成新图片BufferedImage destImage = null;// 计算新图片的长和高int allw = 0, allh = 0, allwMax = 0, allhMax = 0;// 获取总长、总宽、最长、最宽for (int i = 0; i < imgs.size(); i++){BufferedImage img = imgs.get(i);allw += img.getWidth();if (imgs.size() != i + 1){allh += img.getHeight() + 5;} else {allh += img.getHeight();}if (img.getWidth() > allwMax){allwMax = img.getWidth();}if (img.getHeight() > allhMax){allhMax = img.getHeight();}}// 创建新图片if (isHorizontal){destImage = new BufferedImage(allw, allhMax, BufferedImage.TYPE_INT_RGB);} else {destImage = new BufferedImage(allwMax, allh, BufferedImage.TYPE_INT_RGB);}Graphics2D g2 = (Graphics2D) destImage.getGraphics();g2.setBackground(Color.LIGHT_GRAY);g2.clearRect(0, 0, allw, allh);g2.setPaint(Color.RED);// 合并所有子图片到新图片int wx = 0, wy = 0;for (int i = 0; i < imgs.size(); i++){BufferedImage img = imgs.get(i);int w1 = img.getWidth();int h1 = img.getHeight();// 从图片中读取RGBint[] ImageArrayOne = new int[w1 * h1];ImageArrayOne = img.getRGB(0, 0, w1, h1, ImageArrayOne, 0, w1); // 逐行扫描图像中各个像素的RGB到数组中if (isHorizontal) { // 水平方向合并destImage.setRGB(wx, 0, w1, h1, ImageArrayOne, 0, w1); // 设置上半部分或左半部分的RGB} else { // 垂直方向合并destImage.setRGB(0, wy, w1, h1, ImageArrayOne, 0, w1); // 设置上半部分或左半部分的RGB}wx += w1;wy += h1 + 5;}return destImage;}public static List<ImageInfo> word2image(String wordPath,String targetDir){List<ImageInfo> list = Lists.newArrayList();File file = new File(wordPath);InputStream inStream =null;try {inStream = new FileInputStream(file);List<BufferedImage> wordToImg = wordToImg(inStream);IntStream.range(0,wordToImg.size()).forEach(i->{//可以保存图片(每页保存为一张)try {String filePath = (targetDir==null?Constants.TEMP_PATH:targetDir)+File.separator+ i +".png";BufferedImage image = wordToImg.get(i);ImageInfo imageInfo = ImageInfo.builder().width(image.getWidth()).height(image.getHeight()).path(filePath).build();ImageIO.write(image, "jpg", new File(filePath)); //将其保存在C:/imageSort/targetPIC/下synchronized (list){list.add(imageInfo);}}catch (Exception e){log.error("word2pdf error 212",e);}});}catch (Exception e){log.error("word2pdf error",e);}finally {IOUtils.closeQuietly(inStream);}return list;}// 测试工具类public static void main(String[] args){String path = "E:\\网页\\test.docx";new WordUtil().word2image(path,null);}}

PPTUtil.java

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.List;/*** @author yangguang* @date 2023年11月01日 16:11*/
@Slf4j
public class PPTUtil {private final static double IMAGE_SCALE = 8;public static List<ImageInfo> ppt2image(String pptPath, String targetDir){List<ImageInfo> list = Lists.newArrayList();InputStream is = null;HSLFSlideShow ppt = null;try {File file = new File(pptPath);is = new FileInputStream(file);ppt =new HSLFSlideShow(is);Dimension pgSize = ppt.getPageSize();int i=0;for (HSLFSlide slide : ppt.getSlides()) {ImageInfo imageInfo = toPNG(targetDir,pgSize.width, pgSize.height, slide,i);list.add(imageInfo);i++;}} catch (IOException e) {log.error("ppt转换图片失败,{}", e.getMessage());throw new RuntimeException("ppt转换图片失败" + e.getMessage());} finally {try {if (is != null) {is.close();}} catch (IOException e) {e.printStackTrace();}try {if (ppt != null) {ppt.close();}} catch (IOException e) {e.printStackTrace();}}return list;}public static List<ImageInfo> pptx2image(String pptPath,String targetDir){InputStream is = null;XMLSlideShow ppt = null;List<ImageInfo> list = Lists.newArrayList();try {is = new FileInputStream(pptPath);ppt = new XMLSlideShow(is);Dimension pgSize = ppt.getPageSize();int i=0;for (XSLFSlide slide : ppt.getSlides()) {ImageInfo imageInfo = toPNG(targetDir,pgSize.width, pgSize.height, slide,i);list.add(imageInfo);i++;}} catch (IOException e) {log.error("pptx转换图片失败,{}", e.getMessage());throw new RuntimeException("pptx转换图片失败" + e.getMessage());} finally {try {if (is != null) {is.close();}} catch (IOException e) {e.printStackTrace();}try {if (ppt != null) {ppt.close();}} catch (IOException e) {e.printStackTrace();}}return list;}private static ImageInfo toPNG(String targetDir,int pgWidth, int pgHeight, Slide slide,int i) throws IOException {int imageWidth = (int) Math.floor(IMAGE_SCALE * pgWidth);int imageHeight = (int) Math.floor(IMAGE_SCALE * pgHeight);BufferedImage img = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);Graphics2D graphics = img.createGraphics();graphics.setPaint(Color.white);graphics.fill(new Rectangle2D.Float(0, 0, pgWidth, pgHeight));graphics.scale(IMAGE_SCALE, IMAGE_SCALE);slide.draw(graphics);// save the outputString filePath = (targetDir==null?Constants.TEMP_PATH:targetDir)+ File.separator+ i +".png";ImageInfo imageInfo = ImageInfo.builder().width(img.getWidth()).height(img.getHeight()).path(filePath).build();ImageIO.write(img, "jpg", new File(filePath));return imageInfo;}public static void main(String[] args) {new PPTUtil().ppt2image("E:\\网页test.ppt",null);}
}

PdfUtil.java

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.springframework.stereotype.Component;import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.stream.IntStream;/*** @author yangguang* @date 2022年12月20日 9:56*/
@Component
@Slf4j
public class PdfUtil {private static ImageInfo pdftoimageByNum(PDFRenderer renderer, Integer pageNum, String imagePath)throws IOException{BufferedImage image = renderer.renderImageWithDPI(pageNum-1, 296);//image = FileUtil.bufferedImage2Transparent(image);//          BufferedImage image = renderer.renderImage(i, 2.5f);File file1 = new File(imagePath);if(!file1.getParentFile().exists()){file1.getParentFile().mkdirs();}ImageInfo imageInfo = ImageInfo.builder().width(image.getWidth()).height(image.getHeight()).path(imagePath).build();ImageIO.write(image, "PNG", new File(imagePath));return imageInfo;}private static String getFileName(String filepath) {String fileName;filepath = filepath.replaceAll("\\\\",File.separator);if(filepath.contains(File.separator)){fileName = filepath.substring(filepath.lastIndexOf(File.separator) + 1);}else{fileName = filepath;}if(!fileName.endsWith(".pdf")){throw new CustomException("文件格式不正确");}return fileName.substring(0,fileName.lastIndexOf("."));}public static List<ImageInfo> pdf2image(String pdfPath,String targetDir){List<ImageInfo> list = Lists.newArrayList();File file = new File(pdfPath);PDDocument doc=null;try {doc = PDDocument.load(file);PDFRenderer renderer = new PDFRenderer(doc);int pageCount = doc.getNumberOfPages();IntStream.range(0,pageCount).forEach(i->{try {String imagePath = (targetDir==null?Constants.TEMP_PATH:targetDir)+File.separator+ i + ".png";ImageInfo imageInfo = pdftoimageByNum(renderer, i + 1, imagePath);synchronized (list){list.add(imageInfo);}}catch (Exception e){log.error("转换图片失败",e);}});} catch (IOException e) {log.error("转换失败,io异常",e);throw new CustomException("转换失败,io异常");}finally {try {doc.close();} catch (Exception e) {log.error("io异常",e);}}return list;}public static void main(String[] args){List<ImageInfo> a = new PdfUtil().pdf2image("C:\\test.pdf",null);System.out.println(a);}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/129728.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Orangepi Zero2 全志H616】资料及环境搭建

一、资料文档 二、MobaXterm远程连接工具 三、修改登录密码 四、修改内核日志等级 五、配置网络 六、SSH 访问 OrangePi ZERO 2 七、配置 vim 八、基于官方外设开发SDK 一、资料文档 官网资料下载 GitHub&#xff1a;新版本的 orangepi-build 源码 环境搭建&#xff1a;新手配…

vue+asp.net Web api前后端分离项目发布部署

一、前后端项目介绍 1.前端项目是使用vue脚手架进行创建的。 脚手架版本&#xff1a;vue/cli 5.0.8 编译器版本&#xff1a;vs code 1.82.2 2.后端是一个asp.net Core Web API 项目 后端框架版本&#xff1a;.NET 6.0 编译器版本&#xff1a;vs 2022 二、发布部署步骤 第…

安卓抓包之小黄鸟

下载安装 下载地址: https://download.csdn.net/download/yijianxiangde100/88496463 安装apk 即可。 证书配置:

【嵌入式】HC32F07X CAN通讯配置和使用配置不同缓冲器以连续发送

一 背景说明 使用小华&#xff08;华大&#xff09;的MCU HC32F07X实现 CAN 通讯配置和使用 二 原理分析 【1】CAN原理说明&#xff08;参考文章《CAN通信详解》&#xff09;&#xff1a; CAN是控制器局域网络(Controller Area Network, CAN)的简称&#xff0c;是一种能够实现…

HTML基础知识——URL、文本标签、链接标签、图片标签、列表标签

目录 URL&#xff08;统一资源定位符&#xff09; 概述 网址的组成部分 协议 主机 端口 路径 查询参数 锚点 文本标签 示例&#xff1a; 链接标签 示例&#xff1a; 图片标签 示例&#xff1a; 列表标签 示例&#xff1a; URL&#xff08;统一资源定位符&#xff09;…

Go 中的 OOP - 多态性

Go 中的多态性是通过接口实现的。正如我们已经讨论过的&#xff0c;接口在 Go 中是隐式实现的。如果类型为接口中声明的所有方法提供定义&#xff0c;则该类型实现了接口。让我们看看 Go 中如何借助接口实现多态性。 使用接口的多态性 任何为接口的所有方法提供定义的类型都被…

玩转AIGC:如何选择最佳的Prompt提示词?

&#x1f337;&#x1f341; 博主猫头虎 带您 Go to New World.✨&#x1f341; &#x1f984; 博客首页——猫头虎的博客&#x1f390; &#x1f433;《面试题大全专栏》 文章图文并茂&#x1f995;生动形象&#x1f996;简单易学&#xff01;欢迎大家来踩踩~&#x1f33a; &a…

面试经典150题——Day30

文章目录 一、题目二、题解 一、题目 209. Minimum Size Subarray Sum Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, …

周赛369(位运算、分类讨论、记忆化搜索==>动态规划、树形DP)

文章目录 周赛369[2917. 找出数组中的 K-or 值](https://leetcode.cn/problems/find-the-k-or-of-an-array/)位运算模拟 [2918. 数组的最小相等和](https://leetcode.cn/problems/minimum-equal-sum-of-two-arrays-after-replacing-zeros/)分类讨论 [2919. 使数组变美的最小增量…

docker部署MySQL服务

部署 MySQL8.0.35社区版 1.下载镜像 docker pull container-registry.oracle.com/mysql/community-server:8.0.35 查看镜像 docker images 2. 启动MySQL服务器实例 docker run --namemysql8 --restart on-failure -p 3309:3306 -d container-registry.oracle.com/mysql/comm…

探索C++中的不变之美:const与构造函数的深度剖析

W...Y的主页&#x1f60a; 代码仓库分享&#x1f495; &#x1f354;前言&#xff1a; 关于C的博客中&#xff0c;我们已经了解了六个默认函数中的四个&#xff0c;分别是构造函数、析构函数、拷贝构造函数以及函数的重载。但是这些函数都是有返回值与参数的。提到参数与返回…

GPT的使用和反思

GPT的场景 GPT&#xff08;Generative Pre-trained Transformer&#xff09;是一种基于Transformer结构的语言模型&#xff0c;它在自然语言处理领域有广泛的应用。一般情况下&#xff0c;以下几种情况会使用GPT&#xff1a; 文本生成&#xff1a;GPT可以生成自然流畅的文本&a…

零日漏洞预防

零日漏洞&#xff0c;是软件应用程序或操作系统&#xff08;OS&#xff09;中的意外安全漏洞&#xff0c;负责修复该漏洞的一方或供应商不知道该漏洞&#xff0c;它们仍然未被披露和修补&#xff0c;为攻击者留下了漏洞&#xff0c;而公众仍然没有意识到风险。 零日攻击是如何…

Unity中Shader的烘培分支的判断

文章目录 前言一、上一篇文章中所需要的 lightmapUV 只有在烘焙时才会使用1、查看帮助文档后&#xff0c;Unity中判断烘培是否开启&#xff0c;使用的是LIGHTMAP_ON2、我们在 appdata 和 v2f 中&#xff0c;定义第二套UV 前言 Unity中Shader的烘培分支的判断&#xff0c;基于上…

【Linux网络编程_TCP/UDP_字节序_套接字 实现: FTP 项目_局域网聊天项目 (已开源) 】.md updata:23/11/03

文章目录 TCP/UDP对比端口号作用字节序字节序转换api套接字 socket实现网络通讯服务端 逻辑思路demo&#xff1a; 满血版双方通讯/残血版多方通讯服务端 demo客户端 demo FTP 项目实现sever demo:client demo: 局域网多方通讯 配合线程实现sever demo:client demo: TCP/UDP对比…

Django使用APSchedule实现简单定时任务

一、环境依赖 系统&#xff1a;windows10 python: python3.9.0 djnago3.2.0 APScheduler3.10.1 二、django中的配置 1、创建utils包&#xff0c;在包里面创建schedulers包 utils/schedulers/task.py #1、设置 Django 环境&#xff0c;就可以导入项目的模型类这些了 imp…

JDBC数据库连接---附通用的CRUD类

文章目录 JDBC数据库连接1 导包2 编写配置文件3 编写连接数据库代码4 测试工具类5 附加1 通用的CRUD类2 测试CURD类3 测试 JDBC数据库连接 本篇文章以 MySQL 数据库为例&#xff0c;若要切换其他数据库&#xff0c;只需修改 resource文件夹中的 jdbc.properties 配置文件即可。…

解决mysql数据库root用户看不到库

第一种方式&#xff1a; 1.首先停止MySQL服务&#xff1a;service mysqld stop 2.加参数启动mysql&#xff1a;/usr/bin/mysqld_safe --skip-grant-tables & 然后就可以无任何限制的访问mysql了 3.root用户登陆系统&#xff1a;mysql -u root -p mysql 4.切换数据库&#…

【Flutter】Flutter 动画深入解析(1):掌握 AnimationController 的使用

【Flutter】Flutter 动画深入解析(1):掌握 AnimationController 的使用 文章目录 一、前言二、AnimationController 简介三、AnimationController 的主要功能四、Ticker 提供者五、AnimationController 的生命周期六、与 AnimationController 一起使用的 Future七、实际业务…

PS2024免费磨皮滤镜Portraiture插件下载

Portraiture 4是一款适用于LR的人像智能磨皮美化滤镜插件&#xff0c;操作简便、省去了选择蒙版和逐步像素处理的繁琐流程&#xff0c;帮助您实现高效的肖像修饰。快速对照片中皮肤、头发、眉毛等部位进行美化&#xff0c;无需手动调整&#xff0c;大大提高P图效率。全新4版本&…