1) You need to get the byte code of the image and save it.
2) The resulting byte-code is inserted into the program code "as a string".
3) From the recorded byte-code to create an image.
The problem is that it is impossible to save byte code (if you write to txt, it is converted and it can no longer be used).
package image; import java.awt.image.BufferedImage; import java.io. *; import javax.imageio.ImageIO;
public class ImageTest {
private static OutputStream txt; public static void main(String[] args) { try { byte[] imageInByte; BufferedImage originalImage = ImageIO.read(new File("e:/darksouls.jpg")); // ΠΊΠΎΠ½Π²Π΅ΡΡΠ°ΡΠΈΡ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ Π² ΠΌΠ°ΡΡΠΈΠ² Π±Π°ΠΉΡΠΎΠ² ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(originalImage, "jpg", baos); baos.flush(); imageInByte = baos.toByteArray(); baos.close(); // ΠΊΠΎΠ½Π²Π΅ΡΡΠ°ΡΠΈΡ ΠΌΠ°ΡΡΠΈΠ²Π° Π±Π°ΠΉΡΠΎΠ² Π² ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΠ΅ InputStream in = new ByteArrayInputStream(imageInByte); BufferedImage bImageFromConvert = ImageIO.read(in); txt = new FileOutputStream("e:/dark.svg"); //Π·Π°ΠΏΠΈΡΡ ΠΌΠ°ΡΡΠΈΠ²Π° Π±Π°ΠΉΡΠΎΠ² Π² ΡΠ°ΠΉΠ»1 txt.write(imageInByte); ImageIO.write(bImageFromConvert, "jpg", new File("e:/new-darksouls.svg"));//Π·Π°ΠΏΠΈΡΡ ΠΌΠ°ΡΡΠΈΠ²Π° Π±Π°ΠΉΡΠΎΠ² Π² ΡΠ°ΠΉΠ»2 } catch (IOException e) { System.out.println(e.getMessage()); } } } This program converts an image into an array of bytes, and creates a new image from this array.
How to save this array of bytes to create images using a single bytecode (without referring to the original image)?
e:/darksouls.jpgas with a set of bytes. You do not need to load an image and then save it to get a set of bytes - you just need to read the set of bytes from the file. - Pavel Mayorov