A more compressed version would store 3 or 4(RGB/RGBA) bytes of data in each pixel, to maximize data storage.
EDIT: Out of curiosity, I decided to make a quick file->PNG and vice versa converter, source:
Code
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import javax.imageio.ImageIO;
public class IMGEXE {
public static void main(String[] args) {
boolean toimg = true;
File from = null;
if (args.length >= 1) {
from = new File(args[0]);
if (!from.exists() || !from.isFile()) {
System.out.println((from != null ? from.toString() : "") + " does not exist, or is not a file.");
return;
}
}
File to = null;
if (args.length >= 2) {
to = new File(args[1]);
}
toimg = !(from.getName().endsWith(".png"));
try {
to.mkdirs();
to.delete();
to.createNewFile();
}catch (IOException e) {
System.out.println("Could not write: " + to.toString());
return;
}
if (toimg) {
byte[] frm = new byte[] {};
try {
byte[] tmp = Files.readAllBytes(from.toPath());
frm = new byte[tmp.length + 4];
ByteBuffer bb = ByteBuffer.allocate(4);
bb.putInt(tmp.length);
byte[] tmp2 = new byte[4];
bb.position(0);
bb.get(tmp2);
System.arraycopy(tmp2, 0, frm, 0, 4);
System.arraycopy(tmp, 0, frm, 4, tmp.length);
}catch (IOException e) {
System.out.println("Could not read: " + from.toString());
return;
}
int sqr = (int) Math.sqrt(frm.length / 4) + 1; // 4 bytes per pixel @ sqrt so can be squared for number of pixels inside image.
BufferedImage img = new BufferedImage(sqr, sqr, BufferedImage.TYPE_4BYTE_ABGR);
for (int x = 0; x < img.getWidth(); x++) {
for (int y = 0; y < img.getHeight(); y++) {
int index = (y * img.getWidth() + x) * 4;
ByteBuffer bb = ByteBuffer.allocate(4);
for (int p = 0; p < 4; p++) {
if (index + p >= frm.length) {
bb.put(p, (byte) 0x0);
}else {
bb.put(frm[index + p]);
}
}
img.setRGB(x, y, bb.getInt(0));
}
}
try {
ImageIO.write(img, to.getName().substring(to.getName().lastIndexOf(".") + 1), to);
}catch (IOException e) {
System.out.println("Could not write: " + to.toString());
return;
}
}else {
BufferedImage img = null;
try {
img = ImageIO.read(from);
}catch (IOException e) {
System.out.println("Could not read: " + from.toString());
return;
}
if (img != null) {
ByteBuffer bb2 = ByteBuffer.allocate(4);
bb2.putInt(0, img.getRGB(0, 0));
int size = bb2.getInt(0);
byte[] fil = new byte[size];
for (int x = 0; x < img.getWidth(); x++) {
for (int y = 0; y < img.getHeight(); y++) {
int index = (y * img.getWidth() + x) * 4;
if (index == 0) continue;
ByteBuffer bb = ByteBuffer.allocate(4);
bb.putInt(img.getRGB(x, y));
for (int p = 0; p < 4; p++) {
if (index + p - 4 < fil.length) {
fil[index + p - 4] = bb.get(p);
}
}
}
}
try {
Files.write(to.toPath(), fil, StandardOpenOption.WRITE);
}catch (IOException e) {
System.out.println("Could not write: " + from.toString());
return;
}
}
}
System.out.println("Done!");
}
}
I especially like it since it uses the PNG compression algorithms on an EXE, reducing an 11.6mb file to a mere ~5.6 mb. This uses all 4 channels of RGBA, so no space is wasted. It also make some interesting images, similar to OP:
![[Image: 91EWapC.jpg]](https://i.imgur.com/91EWapC.jpg)
This is of Age of Empires 3.