<p>I'm trying to write a program for my Lego Mindstorm NXT, the program is simple, drawing some lines and saving the image in a .png file. So, I thought I'd use BufferedImage and use getGraphics to draw on it, the thing is; if I write the code:</p>

<pre><code>import java.awt.image.BufferedImage;

import lejos.nxt.Button;

public class Main {

    public static void main(String[] args) {
        System.out.println("Test\n");
        BufferedImage bimg = new BufferedImage(300,300, BufferedImage.TYPE_3BYTE_BGR);
        Button.waitForAnyPress();

    }
}
</code></pre>

<p>When I run the program, it freezes for a while in "Linking..." and gives me the following:</p>

<pre><code>Java Heap Space
Java.Lang.OutOfMemory
</code></pre>

<p>So the question is this: How can I use BufferedImage with Lejos without having this problem? And if there's another method of drawing lines and saving the image on a file, it would be very helpful.</p>

<p><strong>EDIT:</strong>
The Java Heap Space is caused by the line </p>

<pre><code>BufferedImage bimg = new BufferedImage(300,300, BufferedImage.TYPE_3BYTE_BGR);
</code></pre>

<p>I've also tried using ImageIO:</p>

<pre><code>import javax.microedition.lcdui.Image;
*
*
Image img = Image.createImage(300, 300);
ImageIO.write((RenderedImage) img, "png", monFichier);
</code></pre>

<p>It gives me the same thing. I don't know but maybe this isn't the right way to create an image with Lejos. What do you think?</p>

CC BY-SA 3.0
2016-03-14T12:54:55.327Z
You shouldn't cross-post the same question here and on stackoverflow, it's spammy.
Mr. Shiny and New 安宇
CC BY-SA 3.0
2016-03-15T17:47:51.257Z
When I launch it, I gives me the following:
Initializing LeJOS JDK at /home/***LeJosPath***
Linking ...
Thank the Java Heap Space comes up. I've edited the question.
DaPoox
CC BY-SA 3.0
2016-03-16T09:36:38.437Z
Ok. I'ill try to look into it then. Thank you.
DaPoox
<nxt><lejos>
Java BufferedImage with Lejos NXT: Java Heap Space
DaPoox
# Java BufferedImage with Lejos NXT: Java Heap Space

(Asked by: username_0 on 2016-03-13)

I'm trying to write a program for my Lego Mindstorm NXT, the program is simple, drawing some lines and saving the image in a .png file. So, I thought I'd use BufferedImage and use getGraphics to draw on it, the thing is; if I write the code:
import java.awt.image.BufferedImage;

import lejos.nxt.Button;

public class Main {

    public static void main(String[] args) {
        System.out.println("Test\n");
        BufferedImage bimg = new BufferedImage(300,300, BufferedImage.TYPE_3BYTE_BGR);
        Button.waitForAnyPress();

    }
}

When I run the program, it freezes for a while in "Linking..." and gives me the following:
Java Heap Space
Java.Lang.OutOfMemory

So the question is this: How can I use BufferedImage with Lejos without having this problem? And if there's another method of drawing lines and saving the image on a file, it would be very helpful.
EDIT:
The Java Heap Space is caused by the line 
BufferedImage bimg = new BufferedImage(300,300, BufferedImage.TYPE_3BYTE_BGR);

I've also tried using ImageIO:
import javax.microedition.lcdui.Image;
*
*
Image img = Image.createImage(300, 300);
ImageIO.write((RenderedImage) img, "png", monFichier);

It gives me the same thing. I don't know but maybe this isn't the right way to create an image with Lejos. What do you think?

**Tags:** nxt, lejos

> **Comments:**
> **username_1**: You shouldn't cross-post the same question here and on stackoverflow, it's spammy.  
> **username_0**: When I launch it, I gives me the following: Initializing LeJOS JDK at /home/***LeJosPath*** Linking ... Thank the Java Heap Space comes up. I've edited the question.  
> **username_0**: Ok. I'ill try to look into it then. Thank you.  

---

## 0 answers

