This commit is contained in:
2022-05-24 17:28:29 +02:00
parent c0b06ea837
commit 79791b395c
16 changed files with 1084 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,22 @@
import javax.swing.JPanel;
import java.awt.*;
import java.awt.Image;
public class AwesomeImage extends JPanel {
private Image img;
public AwesomeImage(Image a) {
super();
this.img = a;
}
@Override
protected void paintComponent(Graphics g) {
Graphics newG = g.create();
if (this.isOpaque()) {
newG.setColor(this.getBackground());
newG.fillRect(0, 0, this.getWidth(), this.getHeight());
}
newG.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
}

Binary file not shown.

View File

@@ -0,0 +1,61 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
public class Image {
public static void main(String[] args) {
try (BufferedReader r = new BufferedReader(new FileReader("image.xpm"))) {
r.readLine(); r.readLine(); r.readLine(); //On skip les 3 première lignes.
String[] infos = r.readLine().replaceAll("[\" ]", " ").trim().split(" ");
System.out.println(Arrays.toString(infos));
int columns = Integer.parseInt(infos[0]);
int rows = Integer.parseInt(infos[1]);
int colorCount = Integer.parseInt(infos[2]);
int charPerPixel = Integer.parseInt(infos[3]);
char[] paletteId = new char[colorCount];
Color[] palette = new Color[colorCount];
for (int i = 0; i < colorCount; i++) {
String colorInfos = r.readLine().replaceAll("[\"]", "");
paletteId[i] = colorInfos.charAt(0);
System.out.println(colorInfos.substring(4, 11));
palette[i] = Color.decode(colorInfos.substring(4, 11));
}
r.readLine(); //On skip la ligne pixels.
BufferedImage bi = new BufferedImage(columns, rows, BufferedImage.TYPE_3BYTE_BGR);
for (int i = 0; i < rows; i++) {
String row = r.readLine().replaceAll("\"", "");
for (int y = 0; y < columns; y++) {
char a = row.charAt(y);
for (int j = 0; j < paletteId.length; j++) {
if (paletteId[j] == a) {
bi.setRGB(y, i, palette[j].getRGB());
}
}
}
}
JFrame j = new JFrame();
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
j.setSize(500 + 50, 500 + 50);
j.setLayout(null);
AwesomeImage a = new AwesomeImage(bi);
a.setLocation(10, 10);
a.setSize(500, 500);
j.add(a);
j.setVisible(true);
} catch (IOException e) {
}
}
}

View File

@@ -0,0 +1,56 @@
/* XPM */
static char *test[] = {
/* columns rows colors chars-per-pixel */
"32 35 15 1",
" c #000000",
". c #731810",
"X c #A52918",
"o c #FF5210",
"O c #D64221",
"+ c #FF8C10",
"@ c #FFBD29",
"# c #FFE739",
"$ c #FFBD4A",
"% c #FFFF63",
"& c #9C8C8C",
"* c #C6B5B5",
"= c #B0D8D0",
"- c #EFDEDE",
"; c #FFFFFF",
/* pixels */
"================================",
"================================",
"=============O====o=============",
"==============O==o#o============",
"==============oO=o@o============",
"==============ooOo+o============",
"==========o===o+o=o=============",
"=========o@o=Oo++o==============",
"=========ooo=o+@+o==============",
"==========o=O++@+oO=============",
"============o+@#@o+O============",
"===========O+@#;#+@+o===========",
"===========O+#;;;+#@o===========",
"===========o@;;;;@#o============",
"=== =======..........======= ===",
"== = = ==..XXOOooOOXX..== = = ==",
"= = =.XXoOO OOoXX.= = =",
"== XXXX % % XXXX ==",
"=== oX XXX XXX Xo ===",
"=====X o$X -& &- X$o X=====",
"=====X o$$o ;;;;;; o$$o X=====",
"===== Xoo$$$ -;oo;- $$$ooX =====",
"===== OoX$Xoo ;;;; ooX$XoO =====",
"===== Xo o O -;;- O o oX =====",
"====== O O = -- = O O ======",
"======= = *= o o =* = =======",
"=========== * oooo * ===========",
"=========== oooooo ===========",
"========== XooooooX ==========",
"========= X XooooooX X =========",
"========= OooOOOOOOooO =========",
"========== oooooooo ==========",
"============ ============",
"================================",
"================================"
};