update commons-imaging to version 1.0.0-alpha6

This commit is contained in:
wyq 2025-05-03 10:16:42 +08:00
parent 80a028992a
commit 01dbe6eb7f
10 changed files with 26 additions and 119 deletions

View File

@ -67,7 +67,6 @@ import javax.swing.Timer;
import javax.swing.event.EventListenerList;
import org.apache.commons.imaging.ImageFormats;
import org.apache.commons.imaging.ImageWriteException;
import org.freehep.graphics2d.VectorGraphics;
import org.freehep.graphicsio.emf.EMFGraphics2D;
import org.freehep.graphicsio.pdf.PDFGraphics2D;
@ -1214,7 +1213,7 @@ public class ChartPanel extends JPanel implements IChartPanel{
public void saveImage(String aFile) {
try {
saveImageSleep(aFile, null);
} catch (PrintException | IOException | InterruptedException | ImageWriteException ex) {
} catch (PrintException | IOException | InterruptedException ex) {
Logger.getLogger(ChartPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
@ -1228,7 +1227,7 @@ public class ChartPanel extends JPanel implements IChartPanel{
* @throws javax.print.PrintException
* @throws java.lang.InterruptedException
*/
public void saveImageSleep(String aFile, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException, ImageWriteException {
public void saveImageSleep(String aFile, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException {
int w, h;
if (this.chartSize == null) {
w = this.getWidth();
@ -1251,7 +1250,7 @@ public class ChartPanel extends JPanel implements IChartPanel{
* @throws javax.print.PrintException
* @throws java.lang.InterruptedException
*/
public void saveImage(String aFile, int width, int height, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException, ImageWriteException {
public void saveImage(String aFile, int width, int height, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException {
if (aFile.endsWith(".ps")) {
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
String mimeType = "application/postscript";
@ -1720,11 +1719,7 @@ public class ChartPanel extends JPanel implements IChartPanel{
Thread.sleep(sleep * 1000);
}
try {
ImageUtil.imageSave(image, fileName, dpi);
} catch (ImageWriteException e) {
e.printStackTrace();
}
ImageUtil.imageSave(image, fileName, dpi);
if (this.hasWebMap()) {
for (Plot plot : this.chart.getPlots()) {

View File

@ -15,7 +15,6 @@ import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLJPanel;
import org.apache.commons.imaging.ImageFormats;
import org.apache.commons.imaging.ImageWriteException;
import org.freehep.graphics2d.VectorGraphics;
import org.freehep.graphicsio.emf.EMFGraphics2D;
import org.freehep.graphicsio.ps.PSGraphics2D;
@ -1264,7 +1263,7 @@ public class GLChartPanel extends GLJPanel implements IChartPanel{
public void saveImage(String aFile) {
try {
saveImageSleep(aFile, null);
} catch (PrintException | IOException | InterruptedException | ImageWriteException ex) {
} catch (PrintException | IOException | InterruptedException ex) {
Logger.getLogger(GLChartPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
@ -1278,7 +1277,7 @@ public class GLChartPanel extends GLJPanel implements IChartPanel{
* @throws PrintException
* @throws InterruptedException
*/
public void saveImageSleep(String aFile, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException, ImageWriteException {
public void saveImageSleep(String aFile, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException {
int w, h;
if (this.chartSize == null) {
w = this.getWidth();
@ -1301,7 +1300,7 @@ public class GLChartPanel extends GLJPanel implements IChartPanel{
* @throws PrintException
* @throws InterruptedException
*/
public void saveImage(String aFile, int width, int height, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException, ImageWriteException {
public void saveImage(String aFile, int width, int height, Integer sleep) throws FileNotFoundException, PrintException, IOException, InterruptedException {
if (aFile.endsWith(".ps")) {
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
String mimeType = "application/postscript";
@ -1596,11 +1595,7 @@ public class GLChartPanel extends GLJPanel implements IChartPanel{
Thread.sleep(sleep * 1000);
}
try {
ImageUtil.imageSave(image, fileName, dpi);
} catch (ImageWriteException e) {
e.printStackTrace();
}
ImageUtil.imageSave(image, fileName, dpi);
if (this.hasWebMap()) {
for (Plot plot : this.chart.getPlots()) {

View File

@ -4,7 +4,6 @@ import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
import org.apache.commons.imaging.ImageReadException;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.meteoinfo.chart.ChartColorBar;
@ -200,9 +199,8 @@ public class EarthGLPlot extends GLPlot {
* Set earth image
* @param imageFile
* @throws IOException
* @throws ImageReadException
*/
public void earthImage(String imageFile) throws IOException, ImageReadException {
public void earthImage(String imageFile) throws IOException {
BufferedImage image = ImageUtil.imageLoad(imageFile);
if (this.surface == null) {
this.earthSurface(50);

View File

@ -10,7 +10,6 @@ import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.Screen;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.*;
import org.apache.commons.imaging.ImageWriteException;
import org.joml.Vector3f;
import org.meteoinfo.chart.GLChart;
import org.meteoinfo.chart.GLChartPanel;
@ -519,7 +518,7 @@ public class JOGLUtil {
try {
//ImageIO.write(image, extension, new File(fn));
ImageUtil.imageSave(image, fn);
} catch (IOException | ImageWriteException ex) {
} catch (IOException ex) {
Logger.getLogger(GLChartPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
@ -539,11 +538,7 @@ public class JOGLUtil {
BufferedImage image = paintViewImage(plot3DGL, width, height, dpi);
if (image != null) {
try {
ImageUtil.imageSave(image, fn, dpi);
} catch (ImageWriteException e) {
e.printStackTrace();
}
ImageUtil.imageSave(image, fn, dpi);
}
}

View File

@ -19,7 +19,6 @@ import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
import org.apache.commons.imaging.ImageFormats;
import org.apache.commons.imaging.ImageWriteException;
import org.meteoinfo.common.MIMath;
import org.meteoinfo.common.PointD;
import org.meteoinfo.common.PointF;
@ -3060,11 +3059,7 @@ import org.xml.sax.SAXException;
paintGraphics(g);
g.dispose();
try {
ImageUtil.imageSave(image, aFile);
} catch (ImageWriteException e) {
e.printStackTrace();
}
ImageUtil.imageSave(image, aFile);
}
}
@ -3123,11 +3118,7 @@ import org.xml.sax.SAXException;
}*/
g.dispose();
try {
ImageUtil.imageSave(image, fileName, dpi);
} catch (ImageWriteException e) {
e.printStackTrace();
}
ImageUtil.imageSave(image, fileName, dpi);
}
}

View File

@ -13,7 +13,6 @@
*/
package org.meteoinfo.geo.mapdata;
import org.apache.commons.imaging.ImageReadException;
import org.meteoinfo.common.DataConvert;
import org.meteoinfo.common.Extent;
import org.meteoinfo.common.PointD;
@ -327,7 +326,7 @@ public class MapDataManage {
* @return Image layer
* @throws IOException
*/
public static ImageLayer readImageFile(String aFile) throws IOException, ImageReadException {
public static ImageLayer readImageFile(String aFile) throws IOException {
String oEx = aFile.substring(aFile.lastIndexOf("."));
String last = oEx.substring(oEx.length() - 1);
String sEx = oEx.substring(0, oEx.length() - 2) + last;

View File

@ -19,8 +19,6 @@ import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
import org.apache.commons.imaging.ImageFormats;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.ImageWriteException;
import org.meteoinfo.common.*;
import org.meteoinfo.common.util.GlobalUtil;
import org.meteoinfo.geo.mapdata.MapDataManage;
@ -6577,36 +6575,7 @@ public class MapView extends JPanel implements IWebMapPanel {
break;
}
try {
ImageUtil.imageSave(image, aFile);
} catch (ImageWriteException e) {
e.printStackTrace();
}
/*String extension = aFile.substring(aFile.lastIndexOf('.') + 1);
if (extension.equalsIgnoreCase("bmp") || extension.equalsIgnoreCase("jpg")) {
BufferedImage bi;
if (extension.equalsIgnoreCase("bmp")) {
bi = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_RGB);
} else {
bi = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
}
Graphics2D g = bi.createGraphics();
if (this.getBackground() != null) {
g.setColor(this.getBackground());
g.fillRect(0, 0, bi.getWidth(), bi.getHeight());
}
paintGraphics(g);
if (extension.equalsIgnoreCase("jpg")) {
BufferedImage newImage = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_RGB);
newImage.createGraphics().drawImage(bi, 0, 0, Color.BLACK, null);
ImageIO.write(newImage, extension, new File(aFile));
} else {
ImageIO.write(bi, extension, new File(aFile));
}
} else {
ImageIO.write(this._mapBitmap, extension, new File(aFile));
}*/
ImageUtil.imageSave(image, aFile);
}
}
@ -6628,12 +6597,6 @@ public class MapView extends JPanel implements IWebMapPanel {
int width = this.getWidth();
int height = this.getHeight();
ImageFormats imageFormat = ImageUtil.getImageFormat(fileName);
/*String formatName = fileName.substring(fileName.lastIndexOf('.') + 1);
if (formatName.equals("jpg")) {
formatName = "jpeg";
saveImage_Jpeg(fileName, width, height, dpi);
return;
}*/
double scaleFactor = dpi / 72.0;
int imageType = imageFormat == ImageFormats.JPEG ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
@ -6643,33 +6606,9 @@ public class MapView extends JPanel implements IWebMapPanel {
at.scale(scaleFactor, scaleFactor);
g.setTransform(at);
paintGraphics(g);
/*for (Iterator<ImageWriter> iw = ImageIO.getImageWritersByFormatName(formatName); iw.hasNext();) {
ImageWriter writer = iw.next();
ImageWriteParam writeParam = writer.getDefaultWriteParam();
ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB);
IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
continue;
}
ImageUtil.setDPI(metadata, dpi);
final ImageOutputStream stream = ImageIO.createImageOutputStream(output);
try {
writer.setOutput(stream);
writer.write(metadata, new IIOImage(image, null, metadata), writeParam);
} finally {
stream.close();
}
break;
}*/
g.dispose();
try {
ImageUtil.imageSave(image, fileName, dpi);
} catch (ImageWriteException e) {
e.printStackTrace();
}
ImageUtil.imageSave(image, fileName, dpi);
}
}
@ -9774,7 +9713,7 @@ public class MapView extends JPanel implements IWebMapPanel {
if (new File(aFile).exists()) {
try {
aLayer = MapDataManage.readImageFile(aFile);
} catch (IOException | ImageReadException ex) {
} catch (IOException ex) {
Logger.getLogger(MapView.class.getName()).log(Level.SEVERE, null, ex);
}
try {

View File

@ -25,7 +25,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-imaging</artifactId>
<version>1.0-alpha3</version>
<version>1.0.0-alpha6</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>

View File

@ -50,9 +50,8 @@ public class ImageUtil {
* @param fileName Image file name
* @return RGB array data
* @throws IOException
* @throws ImageReadException
*/
public static Array imageRead(String fileName) throws IOException, ImageReadException{
public static Array imageRead(String fileName) throws IOException {
String extension = fileName.substring(fileName.lastIndexOf('.') + 1);
BufferedImage image;
if (extension.equalsIgnoreCase("jpg") || extension.equalsIgnoreCase("jpeg")){
@ -92,9 +91,8 @@ public class ImageUtil {
* @param fileName Image file name
* @return Image
* @throws IOException
* @throws ImageReadException
*/
public static BufferedImage imageLoad(String fileName) throws IOException, ImageReadException{
public static BufferedImage imageLoad(String fileName) throws IOException {
String extension = fileName.substring(fileName.lastIndexOf('.') + 1);
BufferedImage image;
if (extension.equalsIgnoreCase("jpg") || extension.equalsIgnoreCase("jpeg")){
@ -240,10 +238,9 @@ public class ImageUtil {
* Save image into a file
* @param data RGB(A) data array
* @param fileName Output image file name
* @throws IOException
* @throws ImageWriteException
* @throws IOException
*/
public static void imageSave(Array data, String fileName) throws IOException, ImageWriteException{
public static void imageSave(Array data, String fileName) throws IOException {
BufferedImage image = createImage(data);
imageSave(image, fileName);
}
@ -252,10 +249,9 @@ public class ImageUtil {
* Save image into a file
* @param image Image
* @param fileName Output image file name
* @throws IOException
* @throws ImageWriteException
* @throws IOException
*/
public static void imageSave(BufferedImage image, String fileName) throws IOException, ImageWriteException{
public static void imageSave(BufferedImage image, String fileName) throws IOException {
ImageFormats format = getImageFormat(fileName);
switch (format) {
case JPEG:
@ -272,9 +268,8 @@ public class ImageUtil {
* @param image Image
* @param fileName Output image file name
* @throws IOException
* @throws ImageWriteException
*/
public static void imageSave(BufferedImage image, String fileName, int dpi) throws IOException, ImageWriteException{
public static void imageSave(BufferedImage image, String fileName, int dpi) throws IOException {
ImageFormats format = getImageFormat(fileName);
switch (format) {
case JPEG:

View File

@ -34,5 +34,5 @@
</Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/>
<Startup MainFormLocation="-6,-6" MainFormSize="1292,764"/>
<Startup MainFormLocation="-6,0" MainFormSize="1348,835"/>
</MeteoInfo>