-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
datahaki
committed
Jan 1, 2024
1 parent
ddeedbf
commit 6cd943e
Showing
6 changed files
with
62 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// adapted by jph | ||
package ch.alpine.tensor.ext; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
import java.util.Iterator; | ||
|
||
import javax.imageio.IIOImage; | ||
import javax.imageio.ImageIO; | ||
import javax.imageio.ImageWriteParam; | ||
import javax.imageio.ImageWriter; | ||
import javax.imageio.stream.ImageOutputStream; | ||
|
||
public enum Jpeg { | ||
; | ||
/** Reference: | ||
* https://stackoverflow.com/questions/13204432/java-how-to-set-jpg-quality | ||
* | ||
* @param bufferedImage | ||
* @param object | ||
* @param quality | ||
* @throws IOException */ | ||
public static void put(BufferedImage bufferedImage, Object object, float quality) throws IOException { | ||
try (ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(object)) { | ||
Iterator<ImageWriter> iterator = ImageIO.getImageWritersByFormatName("jpeg"); | ||
ImageWriter imageWriter = iterator.next(); | ||
ImageWriteParam imageWriteParam = imageWriter.getDefaultWriteParam(); | ||
imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); | ||
imageWriteParam.setCompressionQuality(quality); | ||
imageWriter.setOutput(imageOutputStream); | ||
imageWriter.write(null, new IIOImage(bufferedImage, null, null), imageWriteParam); | ||
imageWriter.dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters