saving JPanel in Solaris

Hi,
I am having a strange problem.
I am trying to save a JPanel as an image (Jpeg or GIF) and am using below given code,

BufferedImage image =(BufferedImage)canvas.createImage(canvas .getWidth(), canvas.getHeight());
Graphics2D g2 = image.createGraphics();
canvas .paint(g2);
g2.dispose();
try{ ImageIO.write(image, "jpeg", new File(filename + ".jpeg")); }
catch(IOException io) { io.printStackTrace(); }

canvas is the JPanel here.
above code is working fine if I run the program in Windows.When I try to run it on Solaris, then
its creating an image file with the given file name but of 0 bytes.

Can anybody help me solve this problem ? am not getting whether its a compatibility problem or some error in the code.
ThanQ in advance.

Comments


  • What happens if you try png format ? works in Solaris ? (have you tried "jpg" instead of "jpeg" ?

    I'm doing almost the same, also with a BufferedImage but in PNG format, and works in Linux and Winblows... no idea in Solaris...
    the code seems correct...

    : Hi,
    : I am having a strange problem.
    : I am trying to save a JPanel as an image (Jpeg or GIF) and am using below given code,
    :
    : BufferedImage image =(BufferedImage)canvas.createImage(canvas .getWidth(), canvas.getHeight());
    : Graphics2D g2 = image.createGraphics();
    : canvas .paint(g2);
    : g2.dispose();
    : try{ ImageIO.write(image, "jpeg", new File(filename + ".jpeg")); }
    : catch(IOException io) { io.printStackTrace(); }
    :
    : canvas is the JPanel here.
    : above code is working fine if I run the program in Windows.When I try to run it on Solaris, then
    : its creating an image file with the given file name but of 0 bytes.
    :
    : Can anybody help me solve this problem ? am not getting whether its a compatibility problem or some error in the code.
    : ThanQ in advance.
    :

  • Thanks for ur reply,

    I tried it with "png " and "jpeg" its not working..
    instead of canvas.paint(), I tried with canvas.paintComponent(g2)...
    the same thing.."not working".
    am really not getting wat to do....
    someone plz help me.

    thanQ.

    :
    : What happens if you try png format ? works in Solaris ? (have you tried "jpg" instead of "jpeg" ?
    :
    : I'm doing almost the same, also with a BufferedImage but in PNG format, and works in Linux and Winblows... no idea in Solaris...
    : the code seems correct...
    :
    : : Hi,
    : : I am having a strange problem.
    : : I am trying to save a JPanel as an image (Jpeg or GIF) and am using below given code,
    : :
    : : BufferedImage image =(BufferedImage)canvas.createImage(canvas .getWidth(), canvas.getHeight());
    : : Graphics2D g2 = image.createGraphics();
    : : canvas .paint(g2);
    : : g2.dispose();
    : : try{ ImageIO.write(image, "jpeg", new File(filename + ".jpeg")); }
    : : catch(IOException io) { io.printStackTrace(); }
    : :
    : : canvas is the JPanel here.
    : : above code is working fine if I run the program in Windows.When I try to run it on Solaris, then
    : : its creating an image file with the given file name but of 0 bytes.
    : :
    : : Can anybody help me solve this problem ? am not getting whether its a compatibility problem or some error in the code.
    : : ThanQ in advance.
    : :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories