This repository has been archived by the owner on Jul 16, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Bump EB4j@2.3.0 - Use ImageUtil in EB4j - Refactoring ImageUtils Signed-off-by: Hiroshi Miura <miurahr@linux.com>
- Loading branch information
Showing
6 changed files
with
58 additions
and
143 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
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
137 changes: 0 additions & 137 deletions
137
src/main/java/io/github/eb4j/ebview/dictionary/epwing/Utils.java
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
package io.github.eb4j.ebview.utils; | ||
|
||
import io.github.eb4j.util.ImageUtil; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.Base64; | ||
|
||
|
||
public final class ImageUtils { | ||
private ImageUtils() { | ||
} | ||
|
||
/** | ||
* convert image data to base64. | ||
* @param format image format. | ||
* @param data image data | ||
* @return base64 string | ||
* @throws IOException when conversion failed | ||
*/ | ||
public static String convertImage2Base64(final String format, final byte[] data) throws IOException { | ||
byte[] bytes; | ||
Base64.Encoder base64Encoder = Base64.getEncoder(); | ||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { | ||
final BufferedImage res = ImageIO.read(new ByteArrayInputStream(data)); | ||
ImageIO.write(res, format, baos); | ||
baos.flush(); | ||
bytes = baos.toByteArray(); | ||
} | ||
return base64Encoder.encodeToString(bytes); | ||
} | ||
|
||
/** | ||
* Convert eb_bitmap to PNG, and convert to Base64 String. | ||
* | ||
* @param data eb_bitmap font data | ||
* @param width image width | ||
* @param height image height | ||
* @return String Base64 encoded PNG data. | ||
* @throws IOException when the image is broken or caused error. | ||
*/ | ||
public static String convertMonoGraphic2Base64(final byte[] data, final int width, final int height) | ||
throws IOException { | ||
return convertImage2Base64("png", ImageUtil.ebBitmap2BMP(data, width, height)); | ||
} | ||
} |
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