Skip to main content

[JAVA2D] Help with image!

3 replies [Last post]
Anonymous

Hey people! =)

I want to know how can I draw a specific area of an image in any
point X, Y of my frame. Example: I have an image of 1024x768 pixels and
I just want to draw the area X=1, Y=600, Width=500 and Height=600 in the points 0, 0 of my frame.

Plz, Could someone help me?

Thanks!

===========================================================================
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".
[att1.html]

Reply viewing options

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

Seems like the most straightforward way to do this
would be to use the drawImage() variant that takes
source and dest rectangles, that is:
public boolean drawImage(Image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
ImageObserver)
Using this method, you can specify the source rect as the area you want
to copy from and the dest rect as the matching area at whatever
(xy) location you want.

I confused by your desire to start from y=600 and grab an area of
height=600 from an image that's only 768 pixels high; I assume that's
a typo (or if not you must want the area clipped at that height?)

Chet.

Rafael wrote:

> Hey people! =)
>
> I want to know how can I draw a specific area of an image in any
> point X, Y of my frame. Example: I have an image of 1024x768 pixels
> and
> I just want to draw the area X=1, Y=600, Width=500 and Height=600 in
> the points 0, 0 of my frame.
>
> Plz, Could someone help me?
>
> Thanks!
> ===========================================================================
> 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".
[att1.html]

Rafael

Ooops!
I noticed my mistake! =)
But I managed to do what I wanted!

Thanks to all for help me!
---rafael
----- Original Message -----
From: Chet Haase
To: JAVA2D-INTEREST@JAVA.SUN.COM
Sent: Wednesday, October 20, 2004 10:22 AM
Subject: Re: [JAVA2D] Help with image!

Seems like the most straightforward way to do this
would be to use the drawImage() variant that takes
source and dest rectangles, that is:
public boolean drawImage(Image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
ImageObserver)
Using this method, you can specify the source rect as the area you want
to copy from and the dest rect as the matching area at whatever
(xy) location you want.

I confused by your desire to start from y=600 and grab an area of
height=600 from an image that's only 768 pixels high; I assume that's
a typo (or if not you must want the area clipped at that height?)

Chet.

Rafael wrote:

Hey people! =)

I want to know how can I draw a specific area of an image in any
point X, Y of my frame. Example: I have an image of 1024x768 pixels and
I just want to draw the area X=1, Y=600, Width=500 and Height=600 in the points 0, 0 of my frame.

Plz, Could someone help me?

Thanks!
=========================================================================== 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".
[att1.html]

Andrew Brygin

Hi Rafael,

one way is to use the combination of the setClip() and drawImage()
methods of the Graphics class:

e.g., assuming dstX, dstY - the position in the frame where image
should be drawn,
srcX, srcY, srcH, srcW - the area of image which should be drawn,
then code can look like this:
g.setClip(dstX, dstY, srcW, srcH);
g.drawImage(src, dstX - srcX, dstY - dstY, null);

On the other hand if you are working with instance of the BufferedImage
then you can simply get subimage
using getSubimage() and draw it with drawImage().

Thanks,
Andrew.

Rafael wrote:

> Hey people! =)
>
> I want to know *how can I draw a specific area of an image in any
> point X, Y of my frame*. Example: I have an image of 1024x768 pixels
> and
> I just want to draw the area X=1, Y=600, Width=500 and Height=600 in
> the points 0, 0 of my frame.
>
> Plz, Could someone help me?
>
> Thanks!
> ===========================================================================
> 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".