Skip to main content

How to "backup" the contents of a volatileImage

3 replies [Last post]
kiamur
Offline
Joined: 2006-11-10

Hi,

I am currently rebuilding quite an old graphics library from software rendered Images to hardware accelerated VolatileImages. I am nearly done with this task, but now I have encountered an old functionality that requies the backup of the Image-content in order to do a scrolling of the zoomed selection over the original scaled graphic.

In the old version it was quite easy to do. They just made a new Image object, and assigned the to be saved image to it:

Image copy = new Image(width, height);
copy = originalImage;
stack.push(copy);

After the assignment, they put the copy on an Object stack, where (inscrolling mode) they can recall this image.

How can I achive tha same functionality when originalImage is of the type VolatileImage? I am pretty sure, that I can't put a volatile image in our stack, as the contents could be lost on th stack without beeing recognized. So my approach was to draw the contents of the volatile image onto an Image-typed object:

Image copy;
copy.getGraphics.drawImage(originalImage, originalImage.getWidth(), originalImage.getHeight(), null);
stack.push(copy);

In the case of recalling the backup, I do the same things the other way around:

originalImage = this.getGraphicsConfiguration.createCompatibleVolatileImage(copy.getWidth(), copy.getHeight());
originalImage.getGraphics.drawImage(copy, copy.getWidth(), copy.getHeight(), null);

Unfortunatly, it does not work as I expected because originalImage does contain after these lines above still the same content as if I never called these lines and not the content I saved earlier in the copy image.

Question: Is this approach appropriate for that what I intend to do?

Thanks,
Maik

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jim Graham

Just to be clear, you are calling "g.drawImage(img, width, height,
null)" in the pseudo-code below which draws "img" at the location w,h -
don't you want to draw it at (0,0) as in:

g.drawImage(img, 0, 0, null);

or was that a typo in the pseudo-code?

...jim

java2d@JAVADESKTOP.ORG wrote:
> Hi,
>
> I am currently rebuilding quite an old graphics library from software rendered Images to hardware accelerated VolatileImages. I am nearly done with this task, but now I have encountered an old functionality that requies the backup of the Image-content in order to do a scrolling of the zoomed selection over the original scaled graphic.
>
> In the old version it was quite easy to do. They just made a new Image object, and assigned the to be saved image to it:
>
> Image copy = new Image(width, height);
> copy = originalImage;
> stack.push(copy);
>
> After the assignment, they put the copy on an Object stack, where (inscrolling mode) they can recall this image.
>
> How can I achive tha same functionality when originalImage is of the type VolatileImage? I am pretty sure, that I can't put a volatile image in our stack, as the contents could be lost on th stack without beeing recognized. So my approach was to draw the contents of the volatile image onto an Image-typed object:
>
> Image copy;
> copy.getGraphics.drawImage(originalImage, originalImage.getWidth(), originalImage.getHeight(), null);
> stack.push(copy);
>
> In the case of recalling the backup, I do the same things the other way around:
>
> originalImage = this.getGraphicsConfiguration.createCompatibleVolatileImage(copy.getWidth(), copy.getHeight());
> originalImage.getGraphics.drawImage(copy, copy.getWidth(), copy.getHeight(), null);
>
> Unfortunatly, it does not work as I expected because originalImage does contain after these lines above still the same content as if I never called these lines and not the content I saved earlier in the copy image.
>
> Question: Is this approach appropriate for that what I intend to do?
>
> Thanks,
> Maik
> [Message sent by forum member 'kiamur' (kiamur)]
>
> http://forums.java.net/jive/thread.jspa?messageID=293223
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

kiamur
Offline
Joined: 2006-11-10

Hi Jim,

You got me . . .

No, it's not a typo, I did it exactly that way because I was too lazy to make me familiar with the parameters of the method. I thought it has to be the width and height of the image to be drawn. That will explain, why I don't get the result I expected (-> the backup image), but why I see the whole existing content of the originalImage.

Anyway, do you think this is an acceptable way to do this task, because what I do is a read operation on a volatile image, what I assume is not recommended because the way from accelerated memory to "normal" memory is not fast at all.

Regards,
Maik

Dmitri Trembovetski

You're right, it's not a good idea to read from volatile images,
so you may need to come up with a different way of scrolling, or
whatever that old application does that requires these "copies".

Also, FYI, there's a VolatileImage.getSnapshot() method which will
give you a snap shot of VolatileImage, no need to do drawImage from
VI to your own created image.

Thanks,
Dmitri

java2d@JAVADESKTOP.ORG wrote:
> Hi Jim,
>
> You got me . . .
>
> No, it's not a typo, I did it exactly that way because I was too lazy to make me familiar with the parameters of the method. I thought it has to be the width and height of the image to be drawn. That will explain, why I don't get the result I expected (-> the backup image), but why I see the whole existing content of the originalImage.
>
> Anyway, do you think this is an acceptable way to do this task, because what I do is a read operation on a volatile image, what I assume is not recommended because the way from accelerated memory to "normal" memory is not fast at all.
>
> Regards,
> Maik
> [Message sent by forum member 'kiamur' (kiamur)]
>
> http://forums.java.net/jive/thread.jspa?messageID=293255
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".