Posted by kiamur
on August 13, 2008 at 8:19 PM PDT
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;
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:
copy.getGraphics.drawImage(originalImage, originalImage.getWidth(), originalImage.getHeight(), null);
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?