Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

S.O.S. Error resizing image in linux. i don't known how solve it

3 views
Skip to first unread message

kox...@gmail.com

unread,
Oct 5, 2004, 2:08:48 AM10/5/04
to
Hello.
Using the bello code i am trying to resize one image (jpg).
this class is using into one web apllication for resizing jpg images.

in windows it runs well but into my linux i doesn't work.

In linux the program is executed to the:
System.out.println("3.-,,,");
try
{
g = output.createGraphics();

it doesn't continuous where it mades g = output.createGraphics();

if i try to execute into linux from the main, its main method appears
this error:


1.-
2.-
3.-,,,
Exception in thread "main" java.lang.InternalError: Can't connect to
X11 window server using ':0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:134)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
at RedimensionamientoDeImagenesJPG.redimensionaJPG(RedimensionamientoDeImagenesJPG.java:36)
at RedimensionamientoDeImagenesJPG.main(RedimensionamientoDeImagenesJPG.java:58)


Can you help me to resizing one JSP image?
thanks

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.PrintStream;
import javax.imageio.ImageIO;

public class RedimensionamientoDeImagenesJPG
{

public RedimensionamientoDeImagenesJPG()
{
}

public void redimensionaJPG(int ancho, String ficheroEntrada,
String ficheroSalida)
{
Graphics2D g = null;
try
{
BufferedImage input = ImageIO.read(new
File(ficheroEntrada));
System.out.println("1.-");
int w = input.getWidth();
int h = input.getHeight();
System.out.println("2.-");
BufferedImage output = new BufferedImage((ancho * w) / w,
(ancho * h) / w, 5);
System.out.println("3.-,,,");
try
{
g = output.createGraphics();
}
catch(Exception ese)
{
ese.printStackTrace();
}
System.out.println("4.-");
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
System.out.println("5.-");
g.drawImage(input, 0, 0, (ancho * w) / w, (ancho * h) / w,
null);
System.out.println("6.-");
ImageIO.write(output, "jpg", new File(ficheroSalida));
System.out.println("7.-");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("ERROR redimensionado imagen: " +
e.getMessage());
}
}

public static void main(String args[])
{
RedimensionamientoDeImagenesJPG f = new
RedimensionamientoDeImagenesJPG();
try
{
f.redimensionaJPG(200, args[0], args[1]);
}
catch(Exception e) { }
}
}

Gordon Beaton

unread,
Oct 5, 2004, 2:28:30 AM10/5/04
to
On 4 Oct 2004 23:08:48 -0700, kox...@gmail.com wrote:
> in windows it runs well but into my linux i doesn't work.
[...]

> Exception in thread "main" java.lang.InternalError: Can't connect to
> X11 window server using ':0.0' as the value of the DISPLAY variable.

The error message means that the application tried to connect to the X
server, but one of the following prevents it:

- you are not running an X server on your linux box.

- you have an X server (maybe on another machine), but ":0.0" is not
the correct value for the DISPLAY environment variable, which the
application uses to determine how to connect to the server.

- there is an X server and the DISPLAY variable is correct, however
you are not authorized to connect to the server, either because it
is owned by another user or because you have not configured your
linux environment correctly.

If you don't actually need a GUI (I haven't looked at your code), you
can specify -Djava.awt.headless=true when you run the application.

See also:
http://java.sun.com/j2se/1.4.2/docs/guide/awt/AWTChanges.html#headless

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e

Babu Kalakrishnan

unread,
Oct 5, 2004, 2:42:30 AM10/5/04
to
kox...@gmail.com wrote:
> Hello.
> Using the bello code i am trying to resize one image (jpg).
> this class is using into one web apllication for resizing jpg images.
>
> in windows it runs well but into my linux i doesn't work.
>
> In linux the program is executed to the:
> System.out.println("3.-,,,");
> try
> {
> g = output.createGraphics();
>
> it doesn't continuous where it mades g = output.createGraphics();
>
> if i try to execute into linux from the main, its main method appears
> this error:
>
>
> 1.-
> 2.-
> 3.-,,,
> Exception in thread "main" java.lang.InternalError: Can't connect to
> X11 window server using ':0.0' as the value of the DISPLAY variable.
> at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)


A lot of AWT related code needs a GraphicsEnvironment to be present on
the platform where the program is being executed. That is the reason
you're getting this exception (no X server).

From JDK 1.4, some of this stuff has been redesigned to work without a
display if you set the System property java.awt.headless to be set. I
think (not 100% sure though) BufferedImages are covered under this. To
check out, try adding the flag -Djava.awt.headless=true to the java
commandline.

BK

kox...@gmail.com

unread,
Oct 5, 2004, 6:44:22 AM10/5/04
to
My linux doesn't X server

My aplication, java class, has one main method for making tests, but
it runs into one web server, tomcat.
is one part from one web application.

how can i solve this problema if is one web application?
you say me for running the java command with the
-Djava.awt.headless=true
but how can i use this into one web application?
thanks
a lot of thanks


Gordon Beaton <n...@for.email> wrote in message news:<41623f0e$1...@news.wineasy.se>...

Babu Kalakrishnan

unread,
Oct 5, 2004, 7:43:09 AM10/5/04
to
kox...@gmail.com wrote:
> My linux doesn't X server
>
> My aplication, java class, has one main method for making tests, but
> it runs into one web server, tomcat.
> is one part from one web application.
>
> how can i solve this problema if is one web application?
> you say me for running the java command with the
> -Djava.awt.headless=true
> but how can i use this into one web application?

Please avoid top posting.


You need to specify the flag at the time of starting Tomcat.

You can modify your Tomcat startup scripts to add the additional flag.

Alternately, the Tomcat startup scripts use an environment
variable"CATALINA_OPTS" which can contain additional commandline
parameters to be passed to "java" at the time of invocation. You can
setup the additional property in this parameter.

BK


0 new messages