Created
April 29, 2019 14:32
-
-
Save hpwit/620da1edcc6343e4b47e11f73c4e5786 to your computer and use it in GitHub Desktop.
bmp to header file
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 com.company; | |
import java.io.*; | |
public class Main { | |
public static void main(String[] args) { | |
File file = new File("C:\\Users\\yves\\Pictures/mar-daniel-garcia-8-bit-art-batman.bmp"); | |
byte[] fileData = new byte[(int) file.length()]; | |
try { | |
DataInputStream dis = new DataInputStream(new FileInputStream(file)); | |
dis.readFully(fileData); | |
dis.close(); | |
int w = ((int) fileData[18] < 0) ? 256 + (int) fileData[18] - 1 : (int) fileData[18]; | |
int w2 = ((int) fileData[19] < 0) ? 256 + (int) fileData[19] - 1 : (int) fileData[19]; | |
//System.out.println("taille x:"+w); | |
//System.out.println("taille x:"+w2); | |
w = w2 * 256 + w; | |
int h = ((int) fileData[22] < 0) ? 256 + (int) fileData[22] - 1 : (int) fileData[22]; | |
// System.out.println("offset:" + (fileData[10] + 256 * fileData[11])); | |
int offset = (int) (fileData[10] + 256 * fileData[11]); | |
//h=84; | |
int de = 4 - 3 * w % 4; | |
if (de == 4) | |
de = 0; | |
w = w * 3; | |
System.out.println("taille x:" + w/3); | |
System.out.println("taille y:" + h); | |
System.out.println("const PROGMEM unsigned char" +file.getName()+"["+w*h+"]={"); | |
for(int y=0;y<h;y++) { | |
for (int x = 0; x < w/3; x++) { | |
System.out.print(String.format("0x%02X ", fileData[y * w + 3 * x + 2 + y * de + offset])+","); | |
System.out.print(String.format("0x%02X ", fileData[y * w + 3 * x + 1 + y * de + offset])+","); | |
System.out.print(String.format("0x%02X ", fileData[y * w + 3 * x + 0 + y * de + offset])+","); | |
}//System.out.print("yves,"); | |
System.out.println(); | |
} | |
System.out.println("}"); | |
} catch (IOException e){System.out.println(e.toString());} | |
// write your code here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment