Xóa bài viết
Bạn có chắc chắn muốn xóa bài viết này không ?
Xóa bình luận
Bạn có chắc chắn muốn xóa bình luận này không ?
How to use Java 8 Encode (Decode) an Image to Base64
https://grokonez.com/java/java-advanced/java-8-encode-decode-an-image-base64
How to use Java 8 Encode (Decode) an Image to Base64
For some purpose like transfering an image through RestfulAPI or saving an image to a DataBase, We need Encoder (Decode) the image to Base64. In the tutorial, JavaSampleApproach will guide you how to use Java 8 for converting.
Related post: Java 8 Base64
I. Technologies for Java 8 Encode Decode an Image to Base64 tutorial
- Eclipse
- Java 8
Note: Prepare an Image at folder C:\base64\image.jpg
II. Java 8 Encode an Image to Base64
public static String encoder(String imagePath) {
String base64Image = "";
File file = new File(imagePath);
try (FileInputStream imageInFile = new FileInputStream(file)) {
// Reading a Image file from file system
byte imageData[] = new byte[(int) file.length()];
imageInFile.read(imageData);
base64Image = Base64.getEncoder().encodeToString(imageData);
} catch (FileNotFoundException e) {
System.out.println("Image not found" + e);
} catch (IOException ioe) {
System.out.println("Exception while reading the Image " + ioe);
}
return base64Image;
}
III. Java 8 Decode an Base64 String to an Image
https://grokonez.com/java/java-advanced/java-8-encode-decode-an-image-base64
How to use Java 8 Encode (Decode) an Image to Base64
Bình luận

{{ comment.user.name }}
Bỏ hay
Hay

Cùng một tác giả

1
0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...

1
0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...

1
0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
Bài viết liên quan

5
8
1. Vài câu lệnh encode với FFMPEG Thường câu lệnh FFMPEG có định dạng : ffmpeg i i: input file Chuyển đổi MPEG sang 3GP ffmpeg i movie1.mpeg a...