2021-08-22
This commit is contained in:
16
imaging/build.gradle.kts
Normal file
16
imaging/build.gradle.kts
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("elex-java")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// https://mvnrepository.com/artifact/org.apache.commons/commons-imaging
|
||||
implementation("org.apache.commons:commons-imaging:1.0-alpha2")
|
||||
|
||||
}
|
||||
43
imaging/src/main/java/kr/pe/elex/examples/CommonsSample.java
Normal file
43
imaging/src/main/java/kr/pe/elex/examples/CommonsSample.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import org.apache.commons.imaging.*;
|
||||
import org.apache.commons.imaging.formats.png.PngConstants;
|
||||
import org.apache.commons.imaging.formats.tiff.constants.TiffConstants;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CommonsSample {
|
||||
public static void main(String... args) throws ImageWriteException, IOException, ImageReadException {
|
||||
readPNG();
|
||||
}
|
||||
|
||||
public static void readPNG() throws IOException, ImageReadException, ImageWriteException {
|
||||
BufferedImage imageSource = Imaging.getBufferedImage(Objects
|
||||
.requireNonNull(Sample.class.getResourceAsStream("/java.png")));
|
||||
Image scaledImage = imageSource.getScaledInstance(16, 16, Image.SCALE_SMOOTH);
|
||||
|
||||
BufferedImage newImage = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = newImage.createGraphics();
|
||||
g.drawImage(scaledImage, 0, 0, null);
|
||||
|
||||
final Map<String, Object> params = new HashMap<>();
|
||||
params.put(ImagingConstants.PARAM_KEY_COMPRESSION,
|
||||
TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED);
|
||||
|
||||
Imaging.writeImage(newImage, new File("out/test-out.ico"), ImageFormats.TIFF, params);
|
||||
//PngConstants.
|
||||
}
|
||||
}
|
||||
57
imaging/src/main/java/kr/pe/elex/examples/Sample.java
Normal file
57
imaging/src/main/java/kr/pe/elex/examples/Sample.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Sample {
|
||||
public static void main(String... args) throws IOException {
|
||||
formats();
|
||||
//readPNG();
|
||||
}
|
||||
|
||||
public static void readPNG() throws IOException {
|
||||
BufferedImage imageSource = ImageIO.read(Objects
|
||||
.requireNonNull(Sample.class.getResourceAsStream("/java.png")));
|
||||
Image scaledImage = imageSource.getScaledInstance(100, 100, Image.SCALE_SMOOTH);
|
||||
|
||||
BufferedImage newImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = newImage.createGraphics();
|
||||
boolean r = g.drawImage(scaledImage, 0, 0, null);
|
||||
|
||||
System.out.println("? " + r);
|
||||
ImageIO.write(newImage, "JPG", new File("out/test-out.jpg"));
|
||||
//ImageIO.write(imageSource, "JPG", new File("test-src-out.jpg"));
|
||||
}
|
||||
|
||||
public static BufferedImage convert(final Image image, final int imageTYpe) {
|
||||
final BufferedImage newImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
|
||||
imageTYpe);
|
||||
|
||||
final Graphics2D g = newImage.createGraphics();
|
||||
g.drawImage(image, 0, 0, null);
|
||||
g.dispose();
|
||||
return newImage;
|
||||
}
|
||||
|
||||
public static void formats(){
|
||||
System.out.println("Writer");
|
||||
for (String item : ImageIO.getWriterFormatNames()) {
|
||||
System.out.println(item);
|
||||
}
|
||||
System.out.println("Reader");
|
||||
for (String item : ImageIO.getReaderFormatNames()) {
|
||||
System.out.println(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
imaging/src/main/resources/java.png
Normal file
BIN
imaging/src/main/resources/java.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
Reference in New Issue
Block a user