Skip to main content

Saving & restoring a region of a VolatileImage

34 replies [Last post]
qu0ll
Offline
Joined: 2006-12-09

I have a VolatileImage and I would like to take a snapshot of a region of it and then restore this region at a later time. I cannot quite figure out how to do it.

So far, I have established that I need to firstly get the snapshot using the image.getSnapshot() method which creates a BufferedImage of the entire volatile image. Then it would seem I need to use the copy the bufferedImage.copyData() method to copy the region I want but that method requires a Raster. So first I have to create Raster. To do this I think I should use the Raster.createWritableRaster() method which requires a SampleModel and a Point. To create the SampleModel it looks like I should be using a SinglePixelPackedSampleModel. To create the SinglePixelPackedSampleModel I need to specify an array of bit masks.

What do I need to put into this bit mask array? Or, is there a simple way of doing this? It seems rather complicated! Perhaps someone has an example of this kind of thing?

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
linuxhippy
Offline
Joined: 2004-01-07

However still keep in mind a VolatileImage can anytime loose its contents!

lg Clemens

qu0ll
Offline
Joined: 2006-12-09

And what happens then? Do I need to be able to "reload" the VI at any time? Unfortunately, the way things are structured at the moment, that information is not always available and that's why I am storing it in a separate image. The VI stores a subregion of a BufferedImage that has been painted over and is used to restore this subregion later. Given this, perhaps I need to use something more persistent like a BI for the subregion and suffer the performance lag (albeit only small).

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

linuxhippy
Offline
Joined: 2004-01-07

Well if a VI is lost its content is undefined - most likely black or white, but by definition simply undefined. There are methods which can be used to query the state of the VI and wether its contents where lost since the last time you asked it.

A VI is usually not a good idea if you would like to store persistent image data in it, its main advantage is that it can be fast rendered-to. BufferedImages are also accalerated for rendering to a native surface (BI->VI/Screen is accalerated, anything->BI is software).

lg Clemens

flar
Offline
Joined: 2003-06-11

If a VI is lost then it will NOP (i.e. nothing can be rendered to it and it will not affect the destination if used as a source) until it is validated again and the buffer is restored. When you validate it you should then fill it in with what you want.

If the VIs are being used to avoid a full repaint then it is likely that your main VI/backbuffer will have been lost if the "saved area" VI is lost which means a full repaint anyway. I say "likely" because it is still possible that your smaller "save" VI can be lost without your main buffer being lost, but in practice your VIs will tend to be lost as a group - most likely because some other DDraw program came to the foreground and pushed surfaces from all other applications out of VRAM. (Dmitri or Chris could probably clarify that better than I can.)

So, if having the contents of the BI survive a VRAM lossage is useful, then saving the contents in the (persistent) BI can serve a purpose, but it will be slower as you've discovered. But, if the saved areas are useless if the main buffer is lost (because a more complete redraw will be necessary?) then I wouldn't worry about it and just use VI's for everything for performance. Also, you have to measure the performance gain of the VI against the very small chance that its contents may be lost and the cost of what you would have to do if it were lost to make a complete determination. Sometimes worrying about preventing the loss is more expensive than just dealing with it when it happens.

Be sure to check for contentsLost on the sub-VIs as well as the main one for completeness. You may be likely to find everything gone all at once, but you want to avoid a problem should just one get lost.

qu0ll
Offline
Joined: 2006-12-09

Hi flar,

Thanks for the info. I like the speed I am getting using VIs and if they all fail together then that's not a problem. But I would like to ensure that I am using them in 100% correct way so that I can recover from any losses.

Is the JavaDoc sufficient info on "best practices" for programming with VI? Is there a link that gives example code of exactly how and when to check for content loss?

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Ken Warner

Dmitri once sent me a link to the docs for BufferStrategy. There's an example
loop there that works -- IF YOU ARE USING BufferStrategy. For just VI -- try
the forums I guess....

http://java.sun.com/javase/6/docs/api/java/awt/image/BufferStrategy.html

The loop described in the docs work for me pretty well. But I'm using
BufferStrategy.

java2d@JAVADESKTOP.ORG wrote:
> Hi flar,
>
> Thanks for the info. I like the speed I am getting using VIs and if they all fail together then that's not a problem. But I would like to ensure that I am using them in 100% correct way so that I can recover from any losses.
>
> Is the JavaDoc sufficient info on "best practices" for programming with VI? Is there a link that gives example code of exactly how and when to check for content loss?
>

===========================================================================
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".

qu0ll
Offline
Joined: 2006-12-09

Ken, unfortunately I cannot use BufferStrategy because I need to manipulate sub-images of a VI. I can't see how that's possible with BufferStrategy.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Dmitri Trembovetski

How about this then?
http://java.sun.com/javase/6/docs/api/java/awt/image/VolatileImage.html

Thanks,
Dmitri

java2d@JAVADESKTOP.ORG wrote:
> Ken, unfortunately I cannot use BufferStrategy because I need to manipulate sub-images of a VI. I can't see how that's possible with BufferStrategy.
>

===========================================================================
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".

Dmitri Trembovetski

And as for multiple volatile images you'll have to
validate each image separately, and loop until
all of them are not lost.

That's a bit of a pain, sorry.

Thanks,
Dmitri

Dmitri Trembovetski wrote:
> How about this then?
> http://java.sun.com/javase/6/docs/api/java/awt/image/VolatileImage.html
>
> Thanks,
> Dmitri
>
> java2d@JAVADESKTOP.ORG wrote:
>> Ken, unfortunately I cannot use BufferStrategy because I need to
>> manipulate sub-images of a VI. I can't see how that's possible with
>> BufferStrategy.
>>
>
> ===========================================================================
> 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".

qu0ll
Offline
Joined: 2006-12-09

In the renderOffScreen() method, why is the Graphics2D object created and disposed of every time you render? Wouldn't it be better to simply call getGraphics() and reuse it each time?

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

flar
Offline
Joined: 2003-06-11

It is unlikely that the graphics creation and disposal would cost you any noticeable amount of time, especially compared to everything else that is going on. It's a lot cleaner to just create and dispose the graphics around the rendering portion of the method than to try to manage a cached copy.

Ken Warner

That's what I've found. That render loop is almost instantaneous
while the pixel pushing takes two orders of magnitude more time.

java2d@JAVADESKTOP.ORG wrote:
> It is unlikely that the graphics creation and disposal would cost you any noticeable amount of time, especially compared to everything else that is going on. It's a lot cleaner to just create and dispose the graphics around the rendering portion of the method than to try to manage a cached copy.
> [Message sent by forum member 'flar' (flar)]
>
> http://forums.java.net/jive/thread.jspa?messageID=247279
>
> ===========================================================================
> 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".

qu0ll
Offline
Joined: 2006-12-09

Ken, how do you create the BufferStrategy in your applet? It seems from the JavaDoc that you need a Window or Canvas. I have neither of those in my applet.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Ken Warner

I use a Canvas. I'll send you my Canvas class code if you want to see
how I do it. Might not make sense because I do all the pixel pushing
stuff in another class.

java2d@JAVADESKTOP.ORG wrote:
> Ken, how do you create the BufferStrategy in your applet? It seems from the JavaDoc that you need a Window or Canvas. I have neither of those in my applet.
>

===========================================================================
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".

qu0ll
Offline
Joined: 2006-12-09

Hi Ken,

Yes, I would love to see how you use the strategy even though it's probably not going to be appropriate for me given that I have a requirement to save subregions of the buffered image which are restored later. I can't see how I can easily do this with a BufferStrategy but I could be wrong.

Just email me with the code if you like - the addy is at the bottom of this message.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Ken Warner

No, what you described is a computation that is not facilitated by
the use of BufferStrategy and VolitileImage. They are for getting
what you have computed on the screen -- fast.

java2d@JAVADESKTOP.ORG wrote:
> Hi Ken,
>
> Yes, I would love to see how you use the strategy even though it's probably not going to be appropriate for me given that I have a requirement to save subregions of the buffered image which are restored later. I can't see how I can easily do this with a BufferStrategy but I could be wrong.
>
> Just email me with the code if you like - the addy is at the bottom of this message.
>

===========================================================================
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".

qu0ll
Offline
Joined: 2006-12-09

OK, well I'd still like to see your Canvas code if you don't object to that as I may be able to use it elsewhere in my application/applet.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Dmitri Trembovetski

And that's a good practice. If BufferStrategy is used
it allows for the implementation to use the most effective
platform-specific way of double-buffering as opposed
to copying VI->screen.

Thanks,
Dmitri

Ken Warner wrote:
> I use the BufferStrategy as an interface to VolitileImage
> and it works great in my applet. I don't make VolitileImage's
> directly in my code.
>
> Dmitri Trembovetski wrote:
>> It would be interesting to find out what was causing
>> the freeze. Would it be possible to create a small
>> test case reproducing the issue?
>>
>> Or if you could just show a piece of code which
>> was using VolatileImages?
>>
>> Thanks,
>> Dmitri
>> Java2D Team
>>
>> java2d@JAVADESKTOP.ORG wrote:
>>
>>> Excellent Dmitri - thank you. I have it working now though not for a
>>> VolatileImage, I had to use a BufferedImage instead. This is because
>>> using the VI caused my applet to freeze when running inside the
>>> browser even though it runs OK when run inside the Eclipse applet
>>> viewer.
>>>
>>> Well I guess that's good enough - it has improved my applet
>>> considerably.
>>>
>>
>> ===========================================================================
>>
>> 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".

===========================================================================
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".

qu0ll
Offline
Joined: 2006-12-09

Hi Dmitri,

The freeze was actually being caused by a concurrency issue which curiously only showed up using VolatileImage. So I am glad I tried it because I wouldn't have seen the problem otherwise.

Now, having got VolatileImage to work, I find that working with a VI is much *slower* than working with a plain BufferedImage. I don't mean the rendering part of it but rather the creating of subimages and then calling drawImage to render into the VI is much slower than using a BI. Why would this be? The code is identical except for using VI instead of BI.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Dmitri Trembovetski

Hi,

java2d@JAVADESKTOP.ORG wrote:
> Hi Dmitri,
>
> The freeze was actually being caused by a concurrency issue which curiously only showed up using VolatileImage. So I am glad I tried it because I wouldn't have seen the problem otherwise.
>
> Now, having got VolatileImage to work, I find that working with a VI is much *slower* than working with a plain BufferedImage. I don't mean the rendering part of it but rather the creating of subimages and then calling drawImage to render into the VI is much slower than using a BI. Why would this be? The code is identical except for using VI instead of BI.
>

Could you post your code?

Note that copying from a VolatileImage to a BufferedImage
will be very slow, you don't want to do that on every frame.
It is acceptable for "do a snapshot once in a while" kind
of stuff, but not in general.

Also, depending on what types of rendering operations you
do BufferedImage may indeed be faster. At least until
6uN comes out which will have better hardware acceleration.

Thanks,
Dmitri

===========================================================================
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".

qu0ll
Offline
Joined: 2006-12-09

Hi Dmitri,

The code is pretty much as per the example you gave. There's no hidden magic. I am rendering lines and gradients mostly if that's any help. I am running with JSE 6 Update N Build 07 at the moment and VolatileImage handling is still slower (much slower) for what I am doing. The VI probably gets blasted on to the screen more quickly than the BufferedImage but my processing of sub-regions is definitely faster with a BI.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

flar
Offline
Joined: 2003-06-11

> Hi Dmitri,
>
> The code is pretty much as per the example you gave.
> There's no hidden magic. I am rendering lines and
> gradients mostly if that's any help. I am running
> with JSE 6 Update N Build 07 at the moment and
> VolatileImage handling is still slower (much slower)
> for what I am doing. The VI probably gets blasted
> on to the screen more quickly than the BufferedImage
> but my processing of sub-regions is definitely
> faster with a BI.

The code that Dmitri gave was an example of how to save a copy of a portion of the VI into a system memory image. The advantage of that technique is that the system memory image will be persistent as long as you hold a reference to it - so you can hold on to it for a long time without losing it. The disadvantage of it is that it requires copying the pixels to main memory - and then back to VRAM if you later restore it. It is not a good technique to use if you need to grab and restore the sub-regions often as he mentioned a few posts ago.

If you are doing something performance critical in all of this then it will be much faster to copy the sub-regions aside into a VI so that the data stays entirely in the graphics memory. Use the same drawImage call that he described, but create the image you are saving it into as a VI instead of a "compatible image" as was shown in his code. The disadvantage of using a VI as the temporary image is that you could run out of VRAM (not likely with today's high memory cards), and that you could lose the contents of the temporary VI since they are volatile (though if you lose those VI contents then you likely lost the contents of your main render buffer as well). All in all, these disadvantages are not important if you need the performance.

The type of image you use for your temporary save/restore images will depend on which type of image is used for your rendering buffer. If it's a VI, then use a VI for the save/restore images if you want performance and only use a system memory image if it must not be volatile. If the main rendering buffer is a BI or a CI then use a BI or CI of the same pixel format.

qu0ll
Offline
Joined: 2006-12-09

Thanks flar for the tip... I have it working now with VolatileImage and it's fast. I guess it didn't like the movement of data between VRAM and system RAM when I was using a combination of BI and VI. Performance is very important in this project. All is well now!

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

qu0ll
Offline
Joined: 2006-12-09

--- Marking question as answered ---

Dmitri Trembovetski

java2d@JAVADESKTOP.ORG wrote:
> I have a VolatileImage and I would like to take a snapshot of a region of it and then restore this region at a later time. I cannot quite figure out how to do it.
>
> So far, I have established that I need to firstly get the snapshot using the image.getSnapshot() method which creates a BufferedImage of the entire volatile image. Then it would seem I need to use the copy the bufferedImage.copyData() method to copy the region I want but that method requires a Raster. So first I have to create Raster. To do this I think I should use the Raster.createWritableRaster() method which requires a SampleModel and a Point. To create the SampleModel it looks like I should be using a SinglePixelPackedSampleModel. To create the SinglePixelPackedSampleModel I need to specify an array of bit masks.
>
> What do I need to put into this bit mask array? Or, is there a simple way of doing this? It seems rather complicated! Perhaps someone has an example of this kind of thing?
>

I'm not quite sure what you're trying to do. If you already
have a BufferedImage with VolatileImage's contents, isn't
that enough?

If you only need to save a part of VolatileImage, you
can just copy part of VI to another image.

You can create an image with the same ColorModel as the VI
using GraphicsConfiguration.createCompatibleImage(w,h)
where GraphicConfiguration is the same that the original
VolatileImage was created from so that both images have
the same format and you don't lose precision (if it was
created using Component.createVolatileImage(), then it's
the GC of the Component).

So:
Image save = gc.createCompatibleImage(saveW, saveH);
// validate the volatile image
do {
vi.validate(gc);
// handle vi validation

Graphics g = save.getGraphics();
g.drawImage(vi, 0, 0, saveW, saveH, srcX, srcY, srcX+saveW, srcY+saveH, null);
} while (vi.contentsLost());

Now you have part of IV in "save". To restore it,
just drawImage it to the VI.

If you needed direct pixel access to the pixels of the saved image,
you can create a BufferedImage of the desired format
('new BufferedImage(saveW, saveH, BufferedImage.TYPE_INT_RGB)', for example)

Thanks,
Dmitri

===========================================================================
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".

qu0ll
Offline
Joined: 2006-12-09

Excellent Dmitri - thank you. I have it working now though not for a VolatileImage, I had to use a BufferedImage instead. This is because using the VI caused my applet to freeze when running inside the browser even though it runs OK when run inside the Eclipse applet viewer.

Well I guess that's good enough - it has improved my applet considerably.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Dmitri Trembovetski

It would be interesting to find out what was causing
the freeze. Would it be possible to create a small
test case reproducing the issue?

Or if you could just show a piece of code which
was using VolatileImages?

Thanks,
Dmitri
Java2D Team

java2d@JAVADESKTOP.ORG wrote:
> Excellent Dmitri - thank you. I have it working now though not for a VolatileImage, I had to use a BufferedImage instead. This is because using the VI caused my applet to freeze when running inside the browser even though it runs OK when run inside the Eclipse applet viewer.
>
> Well I guess that's good enough - it has improved my applet considerably.
>

===========================================================================
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".

Ken Warner

I use the BufferStrategy as an interface to VolitileImage
and it works great in my applet. I don't make VolitileImage's
directly in my code.

Dmitri Trembovetski wrote:
> It would be interesting to find out what was causing
> the freeze. Would it be possible to create a small
> test case reproducing the issue?
>
> Or if you could just show a piece of code which
> was using VolatileImages?
>
> Thanks,
> Dmitri
> Java2D Team
>
> java2d@JAVADESKTOP.ORG wrote:
>
>> Excellent Dmitri - thank you. I have it working now though not for a
>> VolatileImage, I had to use a BufferedImage instead. This is because
>> using the VI caused my applet to freeze when running inside the
>> browser even though it runs OK when run inside the Eclipse applet viewer.
>>
>> Well I guess that's good enough - it has improved my applet considerably.
>>
>
> ===========================================================================
> 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".

qu0ll
Offline
Joined: 2006-12-09

Hey thanks Ken, that looks like a cool idea... i'll give it a go and report back on the results.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Nidel, Mike

Once you have a BufferedImage you could call
getSubImage() and then getRaster() on that to
get a WritableRaster. Then you don't have to
create a Raster at all.

Another way is to get the Raster from the
BufferedImage and use the instance methods
createCompatibleWritableRaster() that will
automatically copy the SampleModel of the
original Raster.

Hope that helps.

> -----Original Message-----
> From: Discussion list for Java 2D API
> [mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of
> java2d@JAVADESKTOP.ORG
> Sent: Tuesday, November 20, 2007 9:00 AM
> To: JAVA2D-INTEREST@JAVA.SUN.COM
> Subject: [JAVA2D] Saving & restoring a region of a VolatileImage
>
> I have a VolatileImage and I would like to take a snapshot of
> a region of it and then restore this region at a later time.
> I cannot quite figure out how to do it.
>
> So far, I have established that I need to firstly get the
> snapshot using the image.getSnapshot() method which creates a
> BufferedImage of the entire volatile image. Then it would
> seem I need to use the copy the bufferedImage.copyData()
> method to copy the region I want but that method requires a
> Raster. So first I have to create Raster. To do this I
> think I should use the Raster.createWritableRaster() method
> which requires a SampleModel and a Point. To create the
> SampleModel it looks like I should be using a
> SinglePixelPackedSampleModel. To create the
> SinglePixelPackedSampleModel I need to specify an array of bit masks.
>
> What do I need to put into this bit mask array? Or, is there
> a simple way of doing this? It seems rather complicated!
> Perhaps someone has an example of this kind of thing?
>
> --
> And loving it,
>
> -Q
> _________________________________________________
> Qu0llSixFour@gmail.com
> (Replace the "SixFour" with numbers to email me) [Message
> sent by forum member 'qu0ll' (qu0ll)]
>
> http://forums.java.net/jive/thread.jspa?messageID=246312
>
> ==============================================================
> =============
> 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".

qu0ll
Offline
Joined: 2006-12-09

OK, thanks for that Mike. But how then do I get the WritableRaster back into the VolatileImage when I come to restore the region?

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Nidel, Mike

I've never used a VolatileImage in my code. The only API I can
see for you to use is createGraphics() to get a Graphics2D, followed
by drawing your Raster back onto the VolatileImage. To draw the
Raster you need to create a BufferedImage from it, and then call
Graphics2D.drawImage().

However, I have no idea if that's how VolatileImage is really meant
to be used... so you should test and be careful.

> -----Original Message-----
> From: Discussion list for Java 2D API
> [mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of
> java2d@JAVADESKTOP.ORG
> Sent: Tuesday, November 20, 2007 9:50 AM
> To: JAVA2D-INTEREST@JAVA.SUN.COM
> Subject: Re: [JAVA2D] Saving & restoring a region of a VolatileImage
>
> OK, thanks for that Mike. But how then do I get the
> WritableRaster back into the VolatileImage when I come to
> restore the region?
>
> --
> And loving it,
>
> -Q
> _________________________________________________
> Qu0llSixFour@gmail.com
> (Replace the "SixFour" with numbers to email me) [Message
> sent by forum member 'qu0ll' (qu0ll)]
>
> http://forums.java.net/jive/thread.jspa?messageID=246324
>
> ==============================================================
> =============
> 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".

qu0ll
Offline
Joined: 2006-12-09

I've decided not to use a VolatileImage but a BufferedImage instead. However, the following code (where image is a BufferedImage):

[code]
BufferedImage subimage = image.getSubimage(x, y, width, height);
WritableRaster raster = subimage.getRaster().createCompatibleWritableRaster();
System.out.println("x=" + raster.getMinX() + ", y=" + raster.getMinY());
[/code]

produces outputs of 0 for all values of x and y which is not what I want. I want getMinX() to have the value of x I pass to the getSubImage() method.

Why am I getting these unwanted results?

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Nidel, Mike

What's the minX on the subimage.getRaster()?

> -----Original Message-----
> From: Discussion list for Java 2D API
> [mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of
> java2d@JAVADESKTOP.ORG
> Sent: Tuesday, November 20, 2007 10:47 AM
> To: JAVA2D-INTEREST@JAVA.SUN.COM
> Subject: Re: [JAVA2D] Saving & restoring a region of a VolatileImage
>
> I've decided not to use a VolatileImage but a BufferedImage
> instead. However, the following code (where image is a
> BufferedImage):
>
> [code]
> BufferedImage subimage = image.getSubimage(x, y, width,
> height); WritableRaster raster =
> subimage.getRaster().createCompatibleWritableRaster();
> System.out.println("x=" + raster.getMinX() + ", y=" +
> raster.getMinY()); [/code]
>
> produces outputs of 0 for all values of x and y which is not
> what I want. I want getMinX() to have the value of x I pass
> to the getSubImage() method.
>
> Why am I getting these unwanted results?
>
> --
> And loving it,
>
> -Q
> _________________________________________________
> Qu0llSixFour@gmail.com
> (Replace the "SixFour" with numbers to email me) [Message
> sent by forum member 'qu0ll' (qu0ll)]
>
> http://forums.java.net/jive/thread.jspa?messageID=246337
>
> ==============================================================
> =============
> 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".