Picture locked after creation with JAI

View: New views
3 Messages — Rating Filter:   Alert me  

Picture locked after creation with JAI

by jai-interest-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi everyone,

my problem is as follows:

I create a picture with JAI and store it with the following method:

ParameterBlock parameterblock = new ParameterBlock();
//bi is the buffered image to save
parameterblock.add(bi);
RenderedOp renderedop = JAI.create("AWTImage", parameterblock);
JAI.create("filestore", renderedop, s, "jpeg");

s is the fileName String.

Now when this method has passed the image is saved correctly to the disk but when i try to open it it cannot be displayed. i need to restart the tomcat server the abovementioned code is executed in to somehow "unlock" the image from a lock.

how can i avoid this sort of lock so that i can open the saved image even if the server hasnt been restarted since saving the pic.

greets und thanks in forward

andreas
[Message sent by forum member 'andreeeas' (andreeeas)]

http://forums.java.net/jive/thread.jspa?messageID=285344

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


RE: Picture locked after creation with JAI

by Nidel, Mike :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

First, I don't think you need to do the AWTImage operation.
This is to convert a java.awt.Image to a RenderedImage (of
which RenderedOp is an implementation). Since BufferedImage
is BOTH a RenderedImage implementation AND a java.awt.Image
subclass, you can pass your BufferedImage directly to a
JAI operator.

Secondly, if you only want to write a simple JPEG, I
recommend that instead of doing

JAI.create("filestore"...);

you should instead use

ImageIO.write(bi, "jpeg", new File("/your/file.jpg"));


This is because "filestore" uses the JAI codec which is
deprecated and might eventually go away, while ImageIO is
the preferred mechanism in Java 1.4+ to read/write images.

In any case, if you MUST use the JAI operator, you should
use "encode" instead of "filestore" because this lets you
pass in the OutputStream and close it yourself when the
operation is complete. Then your file will no longer be
locked.


Mike
 

> -----Original Message-----
> From: jai-interest@...
> [mailto:jai-interest@...]
> Sent: Wednesday, July 09, 2008 7:40 AM
> To: interest@...
> Subject: [JAI] Picture locked after creation with JAI
>
> Hi everyone,
>
> my problem is as follows:
>
> I create a picture with JAI and store it with the following method:
>
> ParameterBlock parameterblock = new ParameterBlock(); //bi is
> the buffered image to save parameterblock.add(bi); RenderedOp
> renderedop = JAI.create("AWTImage", parameterblock);
> JAI.create("filestore", renderedop, s, "jpeg");
>
> s is the fileName String.
>
> Now when this method has passed the image is saved correctly
> to the disk but when i try to open it it cannot be displayed.
> i need to restart the tomcat server the abovementioned code
> is executed in to somehow "unlock" the image from a lock.
>
> how can i avoid this sort of lock so that i can open the
> saved image even if the server hasnt been restarted since
> saving the pic.
>
> greets und thanks in forward
>
> andreas
> [Message sent by forum member 'andreeeas' (andreeeas)]
>
> http://forums.java.net/jive/thread.jspa?messageID=285344
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@...
> For additional commands, e-mail: interest-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: RE: Picture locked after creation with JAI

by jai-interest-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That did it Mike!

Thanks alot, i just had to replace the jai.create with the alternative operation in the imagio class, which absolutely fits my needs.

So thanks again for the fast help ;-)

Greets

Andreas
[Message sent by forum member 'andreeeas' (andreeeas)]

http://forums.java.net/jive/thread.jspa?messageID=285384

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...

LightInTheBox - Buy quality products at wholesale price