Skip to content

Instantly share code, notes, and snippets.

@LeftistTachyon
Created April 14, 2020 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeftistTachyon/7148b87f1daad4ea7b8c1fe9b62728df to your computer and use it in GitHub Desktop.
Save LeftistTachyon/7148b87f1daad4ea7b8c1fe9b62728df to your computer and use it in GitHub Desktop.
A better way to create custom pfp's in DSi Paint
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