

Coding with Paint (FIXED) - mosh_java

i noticed this topic (http://i.imgur.com/QlGpd.gif) shared here, so i made a code to generate Bitmaps using text :D<p>import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;<p>/<i></i>
 *
 * @author MErsan
 <i>/
public class BitmapToText {<p><pre><code>    static final int BITMAP_SMALLEST_SIZE = 56;//Calculated using 1*1 pixels image

    public static void main(String[] args) throws IOException {
        String text = "hello every one\n my name is Mosh Ersan";

        text = text.toUpperCase();
        byte[] textData = text.getBytes();
        int dataLen = textData.length;
        int pixels = dataLen / 3;
        pixels += (dataLen % 3);

        int bitmapWidth = (int) Math.sqrt(pixels);
        int bitmapHeight = bitmapWidth;

        int dataSize = (bitmapHeight * bitmapWidth);

        byte[] initialData = new byte[54];
        Arrays.fill(initialData, (byte) 0);

        byte[] endData = new byte[2];
        Arrays.fill(endData, (byte) 0);

        initialData[0] = (byte) 66;//Deafult Values
        initialData[1] = (byte) 77;//Deafult Values
        initialData[2] = (byte) (BITMAP_SMALLEST_SIZE + dataSize); //File Size in Bytes
        initialData[10] = (byte) 54;//Points to Pixels Array
        initialData[14] = (byte) 40;// I Don't
        initialData[18] = (byte) bitmapWidth;//Bitmap Width
        initialData[22] = (byte) bitmapHeight;//Bitmap Height
        initialData[26] = (byte) 1;// :S
        initialData[28] = (byte) 24;//Color Depth
        initialData[34] = (byte) 8; // And this :D

        File f = new File("D://test.bmp");
        if (!f.exists()) {
            f.createNewFile();
        }
        FileOutputStream fos = new FileOutputStream(f);

        fos.write(initialData);
        fos.write(textData);
        fos.write(endData);

        fos.close();

    }
}</code></pre>
======
gamerwho
I covered this .gif picture in-depth on my blog: <http://bit.ly/yPuel0>

This script of yours basically automates the steps needed to create a bitmap
with text.

~~~
mosh_java
Thats was very nice

