修改皮肤

支持jpm 和jp2
修改 盘号名称
master
zhanghai 2 years ago
parent af4d2f6e28
commit e38935c147

@ -94,6 +94,13 @@
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.im4java</groupId>
<artifactId>im4java</artifactId>
<version>1.4.0</version> <!-- 请检查最新版本 -->
</dependency>

@ -7,6 +7,8 @@ import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.Imaging;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@ -16,7 +18,7 @@ import java.util.*;
@Slf4j
public class FenpanService {
public void fenpan(String saveUrl,String readUrl){
public void fenpan(String saveUrl, String readUrl) {
try {
FenpanService main = new FenpanService();
Map<String, Zong> zongMap = main.readFile(readUrl);
@ -85,7 +87,7 @@ public class FenpanService {
Config.loadConfig();
String saveUrl = Config.getParam("file.save.url");
String readUrl = Config.getParam("file.read.url");
new FenpanService().fenpan(saveUrl,readUrl);
new FenpanService().fenpan(saveUrl, readUrl);
}
@ -112,28 +114,46 @@ public class FenpanService {
File[] files = sourceFile.listFiles();
for (File file : files) {
//非图片模式,跳过。
if(!(file.getName().endsWith(".jpg") || file.getName().endsWith(".png")
if (!(file.getName().endsWith(".jpg") || file.getName().endsWith(".png")
|| file.getName().endsWith(".jpeg") || file.getName().endsWith(".tif")
|| file.getName().endsWith(".tiff"))){
continue;
|| file.getName().endsWith(".tiff")) || file.getName().endsWith(".jp2") || file.getName().endsWith(".jpm")) {
continue;
}
try {
ImageInfo imageInfo = Imaging.getImageInfo(file);
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
Document document = new Document(width, height, physicalHeightDpi);
documentList.add(document);
} catch (IOException e) {
FileUtils.delete(file);
throw new RuntimeException("非图片格式", e);
} catch (ImageReadException e) {
FileUtils.delete(file);
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
FileUtils.delete(file);
if (file.getName().endsWith(".jp2") || file.getName().endsWith(".jpm")) {
// 读取 JPEG 2000 图像文件
try {
BufferedImage image = ImageIO.read(file);
int height = image.getHeight();
int width = image.getWidth();
Document document = new Document(width, height, 300);
documentList.add(document);
} catch (IOException e) {
throw new RuntimeException(e);
}
// ImageInfo imageInfo = Imaging.getImageInfo(inputFile);
} else {
try {
ImageInfo imageInfo = Imaging.getImageInfo(file);
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
Document document = new Document(width, height, physicalHeightDpi);
documentList.add(document);
} catch (IOException e) {
FileUtils.delete(file);
throw new RuntimeException("非图片格式", e);
} catch (ImageReadException e) {
FileUtils.delete(file);
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
FileUtils.delete(file);
}
}
}
piece.put(documentList);
}
@ -160,7 +180,7 @@ public class FenpanService {
zongMap.put(zongName, zong);
}
for(String zongName: zongMap.keySet()){
for (String zongName : zongMap.keySet()) {
Zong zong = zongMap.get(zongName);
File zongfile = new File(zong.getAbsolutePath());
File[] files = zongfile.listFiles();
@ -183,7 +203,7 @@ public class FenpanService {
};
Arrays.sort(files, fileComparator);
for(File file:files){
for (File file : files) {
Roll roll = rollMap.get(file.getName());
zong.put(roll);
}

@ -19,18 +19,30 @@ public class MyApplication {
public static void main(String[] args) throws IOException {
Config.loadConfig();
// 获取系统支持的外观信息
UIManager.LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();
// 遍历可用的外观并设置所选外观
for (UIManager.LookAndFeelInfo info : lookAndFeels) {
if ("Nimbus".equals(info.getName())) { // 选择Nimbus外观
try {
UIManager.setLookAndFeel(info.getClassName());
break;
} catch (Exception e) {
e.printStackTrace();
}
}
// UIManager.LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();
//
// // 遍历可用的外观并设置所选外观
// for (UIManager.LookAndFeelInfo info : lookAndFeels) {
// if ("Nimbus".equals(info.getName())) { // 选择Nimbus外观
// try {
// UIManager.setLookAndFeel(info.getClassName());
// break;
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (UnsupportedLookAndFeelException e) {
throw new RuntimeException(e);
}
SwingUtilities.invokeLater(() -> createAndShowGUI());

@ -11,6 +11,8 @@ import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.Imaging;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@ -71,25 +73,42 @@ public class SuoyinService {
//非图片模式,跳过。
if(!(docfile.getName().endsWith(".jpg") || docfile.getName().endsWith(".png")
|| docfile.getName().endsWith(".jpeg") || docfile.getName().endsWith(".tif")
|| docfile.getName().endsWith(".tiff"))){
|| docfile.getName().endsWith(".tiff")|| file.getName().endsWith(".jp2") || file.getName().endsWith(".jpm"))){
continue;
}
try {
ImageInfo imageInfo = Imaging.getImageInfo(docfile);
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
Document document = new Document(width, height, physicalHeightDpi);
documentList.add(document);
} catch (IOException e) {
if (file.getName().endsWith(".jp2") || file.getName().endsWith(".jpm")) {
// 读取 JPEG 2000 图像文件
try {
BufferedImage image = ImageIO.read(file);
int height = image.getHeight();
int width = image.getWidth();
Document document = new Document(width, height, 300);
documentList.add(document);
} catch (IOException e) {
throw new RuntimeException(e);
}
// ImageInfo imageInfo = Imaging.getImageInfo(inputFile);
} else {
try {
ImageInfo imageInfo = Imaging.getImageInfo(docfile);
int height = imageInfo.getHeight();
int width = imageInfo.getWidth();
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
Document document = new Document(width, height, physicalHeightDpi);
documentList.add(document);
} catch (IOException e) {
// FileUtils.delete(file);
throw new RuntimeException("非图片格式", e);
} catch (ImageReadException e) {
throw new RuntimeException("非图片格式", e);
} catch (ImageReadException e) {
// FileUtils.delete(file);
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
// FileUtils.delete(file);
}
}
}
pieces.put(documentList);
pieceList.add(pieces);

@ -1,20 +1,91 @@
import com.github.jaiimageio.jpeg2000.impl.J2KImageReader;
import com.github.jaiimageio.jpeg2000.impl.J2KImageReaderSpi;
import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.ImageWriteException;
import org.apache.commons.imaging.Imaging;
import org.apache.commons.imaging.common.ImageMetadata;
import org.apache.commons.imaging.common.RationalNumber;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageInputStream;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
public class Jpm2 {
public static void main(String[] args) {
try {
// 指定 JP2 图像文件路径
String filePath = "C:\\Users\\zhanghai\\Documents\\WeChat Files\\wxid_wexo4ubjorso22\\FileStorage\\File\\2023-11\\1.jpm"; // 替换成你的 JP2 图像文件路径
// 创建 ImageInputStream
ImageInputStream iis = ImageIO.createImageInputStream(new File(filePath));
// 获取 DPI 信息
float xDpi = getDPI(iis, "HorizontalPixelSize");
float yDpi = getDPI(iis, "VerticalPixelSize");
System.out.println("X DPI: " + xDpi);
System.out.println("Y DPI: " + yDpi);
// 关闭 ImageInputStream
iis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static float getDPI(ImageInputStream iis, String elementName) {
float dpi = -1.0f;
try {
// 获取 ImageReader
Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
if (readers.hasNext()) {
ImageReader reader = readers.next();
// 设置输入流
reader.setInput(iis);
// 获取第一个图像的元数据
IIOMetadata metadata = reader.getImageMetadata(0);
// 获取 DPI 信息
String value = getMetadataValue(metadata, elementName);
if (value != null) {
dpi = Float.parseFloat(value);
}
// 关闭 ImageReader
reader.dispose();
}
} catch (Exception e) {
e.printStackTrace();
}
return dpi;
}
private static String getMetadataValue(IIOMetadata metadata, String elementName) {
String value = null;
String[] names = metadata.getMetadataFormatNames();
for (String name : names) {
IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(name);
value = getMetadataValueRecursive(root, elementName);
if (value != null) {
break;
}
}
return value;
}
private static String getMetadataValueRecursive(IIOMetadataNode node, String elementName) {
if (node.getNodeName().equals(elementName)) {
return node.getAttribute("value");
}
for (int i = 0; i < node.getLength(); i++) {
String value = getMetadataValueRecursive((IIOMetadataNode) node.item(i), elementName);
if (value != null) {
return value;
}
}
return null;
}
}

@ -39,7 +39,7 @@ public class JpmTest {
// int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
String filePath = "C:\\Users\\zhanghai\\Documents\\WeChat Files\\wxid_wexo4ubjorso22\\FileStorage\\File\\2023-11\\JP2/16-35数转模 - 0001.jp2"; // 替换成你的 JP2 图像文件路径
String filePath = "C:\\Users\\zhanghai\\Documents\\WeChat Files\\wxid_wexo4ubjorso22\\FileStorage\\File\\2023-11\\1.jpm"; // 替换成你的 JP2 图像文件路径
try {
// 读取 JPEG 2000 图像文件
@ -57,7 +57,7 @@ public class JpmTest {
e.printStackTrace();
}
new JpmTest().viewExif(filePath);
// new JpmTest().viewExif(filePath);
}
// public static void main3(String[] args) {

Loading…
Cancel
Save