Created
April 14, 2020 20:56
-
-
Save LeftistTachyon/7148b87f1daad4ea7b8c1fe9b62728df to your computer and use it in GitHub Desktop.
A better way to create custom pfp's in DSi Paint
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
package package3; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.util.Base64; | |
import org.apache.commons.io.FileUtils; | |
/** | |
* A program that converts a given image into Base 64. The data is written to a | |
* file named "egg.txt"<br> | |
* Please note that Apache Commons IO is required for this code to function | |
* properly. I used version 2.6, as Baeldung suggested. | |
* | |
* @author GuiedGui | |
*/ | |
public class NewerMain3 { | |
/** | |
* The main method; the entry point of the application | |
* | |
* @param args the command line arguments | |
* @throws IOException in case a bad image or bad output is specified | |
*/ | |
public static void main(String[] args) throws IOException { | |
// the path of the file | |
String filePath = "shigu.png"; | |
// reading the contents of the file as a byte array | |
byte[] fileContent = FileUtils.readFileToByteArray(new File(filePath)); | |
// Java 8 conversion of byte array to Base 64 | |
// make sure the "data" part before the semicolon matches the | |
// MIME type of the given image | |
String encodedString = "data:image/png;base64," | |
+ Base64.getEncoder().encodeToString(fileContent); | |
// writing to a file | |
try (PrintWriter out = new PrintWriter("egg.txt")) { | |
out.println(encodedString); | |
System.out.println("Done!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment