help with OutOfMemoryError

Why i have got such a message:Exception in thread "main" java.lang.OutOfMemoryErrorwhen i create a BufferedImage:BufferedImage buf ;buf = new BufferedImage(4000,4000,BufferedImage.TYPE_INT_RGB)
[235 byte] By [richie03] at [2007-9-27 14:27:20]
# 1
Wow. Do you really need the image to be that big? Try lowering the first to parameters to something smaller, like to the size of your screen resolution or something.
jlbpa at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 2
sorry not to reply earlier.In fact i must create an image that contain several images of 768*576 dimension each one.THat will give me one very big like 10000*10000 maximum.If you have an idea that will be great...
richie03 at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 3
Well with a bit depth of 32 one image of dimension 768x576 is going to take 1.687 megs of RAM. A 10000x10000 image would be over 381 megs of RAM. What are you trying to accomplish? Maybe there is another way.
zparticle at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 4

first i thank you for your attention.

I m working on a project that takes with a camera TIFF images (dimension 768*576) of a plan(1500 meters*1500 meters).

I want to paste the images of a region of interest in a big images to make effect on it after.

So i obtain image of 9000*9000 and i can't do that because i must affect memory size when i compile it and i don't know how i can't do that.

Sorry for my poor written langage but i'm not english...

richie03 at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 5
furthermore the image taken by the camera is in gray 8 bits
richie03 at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 6

Well I'm still not quite clear on your goal but how about creating thumbnails of the original images and making you larger picture out those?

Is this something that is interactive with a user? Does the user want to zoom in on the pictures or something?

What is the big picture (composite of the smaller ones) for, how will it be used?

zparticle at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 7

The big picture is composite of the smaller ones:

it will be use (the big picture) with specific operation of the freeware imageJ.

Here is my code:

/**************************/

/***Biblioth鑡ues***/

/**************************/

import java.io.* ;

import java.util.* ;

import java.lang.* ;

import javax.swing.* ;

import java.awt.* ;

import java.awt.image.* ;

import javax.media.jai.* ;

import com.sun.media.jai.codec.* ;

public class ComposeImage extends JPanel

{

/**********************/

/***Attributs***/

/**********************/

/* dimension de l'image globale reconstitu閑 */

int width ;

int height ;

/* nom du fichier jpg qui repr閟ente l'image d'une r間ion reconstitu閑 */

String fileName ;

/* Nom de l'image globale reconstitu閑 */

String NomImageGlobale ;

/**************************************************/

/*** Constructeur de la classe programme***/

/**************************************************/

/* constructeur de la classe Programme */

public ComposeImage(int w,int h,String img)

{

try

{

this.width = w ;

this.height = h ;

this.NomImageGlobale = img ;

BufferedImage bufimg = new BufferedImage(this.get_width()*1,this.get_height()*1,BufferedImage.TYPE_INT_RGB) ;

Graphics g2D = bufimg.createGraphics();

Image imtemp1 = new ImageIcon("image3.jpg").getImage() ;

Image imtemp2 = new ImageIcon("image4.jpg").getImage() ;

g2D.drawImage(imtemp1,0,0,null) ;

g2D.drawImage(imtemp2,100,100,null) ;

g2D.dispose() ;

File file = new File(this.NomImageGlobale+".tif");

FileOutputStream out = new FileOutputStream(file);

TIFFEncodeParam param = new TIFFEncodeParam() ;

param.setCompression(TIFFEncodeParam.COMPRESSION_NONE) ;

ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF",out,param);

encoder.encode(bufimg);

out.close() ;

}

catch (Exception ex) {}

}

/**********************/

/***M閠hodes***/

/**********************/

/* retourne la valeur de la hauteur des images enregistr閑s par la cam閞a */

public int get_height() { return this.height ; }

/* retourne la valeur de la largeur des images enregistr閑s par la cam閞a */

public int get_width() { return this.width ; }

/* affecte une valeur ?la hauteur des images enregistr閑s par la cam閞a */

public void set_height(int s1) { this.height = s1 ; }

/* affecte une valeur ?la largeur des images enregistr閑s par la cam閞a */

public void set_width(int s2) { this.width = s2 ; }

}

It s just an exemple (hope you don't hate french langage!)

richie03 at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 8

Well first off I think you want to use TYPE_USHORT_GRAY not TYPE_INT_RGB. That should dramtically reduce the amount of memory the image is going to take. So an 8 bit gray scale image at 10000x10000 should take 95.367 megs of memory.

Also you can increase the heap size available using the -Xmx command line option. I'm pretty sure that you specify the memory in kilobytes so -Xmx64000 is 64 thousand K or 64 meg. Try -Xmx128000 to make the heap 128 meg.

zparticle at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 9
frech doesn't bother me at all :)
zparticle at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 10
Opps it's -Xmx128m for 128 meg
zparticle at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 11
i have forgot to say that i work on a window operating system with 128k of memory(SDRAM)1. Don't you thing it is a problem to run my program.2. after which commande do you type Xm...Thank for your help
richie03 at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 12
Well if you only have 128 megs of RAM that might be a problem. Try setting it to 100 meg. Which OS 95,98,ME,Win2K,XP ? You will have to play around with the memory setting until you can get it to work. Otherwise you'll need to get more memory.java -Xmx128m MyClass
zparticle at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 13
I work on win2000i type: "C:\j2sdk1.4.0_01\bin>java -Xmx100m ComposeImageFrame.class"that gives: "Exception in thread "main" java.lang.NoClassDefFoundError: ComposeImageFrame/class"
richie03 at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 14
That works.......:) I thank you a lot, i m not going crazy..:)
richie03 at 2007-7-5 22:18:18 > top of Java-index,Other Topics,Java Game Development...
# 15

> I work on win2000

> i type: "C:\j2sdk1.4.0_01\bin>java -Xmx100m

> ComposeImageFrame.class"

> that gives: "Exception in thread "main"

> java.lang.NoClassDefFoundError:

> ComposeImageFrame/class"

c:\j2sdk1.4.0_01\bin> java -Xmx100m ComposeImageFrame

The .class is implied and actually problematic. If you type the .class, it thinks that "ComposeImageFrame" is a package and that you are attempting to execute the "class.class" file in that package.

tvynra at 2007-7-18 11:37:44 > top of Java-index,Other Topics,Java Game Development...
# 16
Yatjack NUMBAH 1
kaze0a at 2007-7-18 11:37:44 > top of Java-index,Other Topics,Java Game Development...