Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Need help with drawImage()  (Read 1297 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Ninja


Medals: 35
Projects: 5


I always win!


« Posted 2005-10-29 00:03:34 »

I simply don't understand this method, can anyone explain to me how this works or any links to tutorials on this?

I know (dx1,dy1,dx2,dy2) is the rectangle to draw (right?) ... but the (sx1,sy1,sx2,sy2) has got me totally confused.

I read this example (http://www.javaworld.com/javaworld/javatips/jw-javatip32.html) over and over again, but just couldn't understand how he can draw that image (first image).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public abstract boolean drawImage(Image img,
                                  int dx1,
                                  int dy1,
                                  int dx2,
                                  int dy2,
                                  int sx1,
                                  int sy1,
                                  int sx2,
                                  int sy2,
                                  ImageObserver observer)

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Tzan

Junior Member





« Reply #1 - Posted 2005-10-29 00:41:30 »

This drawImage method take an image (source, sx,sy) and draws that same image to the graphics context used in g.
It draws it there with a new set of coordinates (destination dx, dy) and these coordinates could be set up to stretch, shrink or flip the image.

Also the source coords could specify a smaller area in the source image to draw, so you end up with a cropped image.

The first image is an example of image cropping, he took a small chunk of the original image by using sx,sy that defined a smaller area than the entire image.

Offline appel

JGO Ninja


Medals: 35
Projects: 5


I always win!


« Reply #2 - Posted 2005-10-29 03:23:58 »

This drawImage method take an image (source, sx,sy) and draws that same image to the graphics context used in g.
It draws it there with a new set of coordinates (destination dx, dy) and these coordinates could be set up to stretch, shrink or flip the image.

Also the source coords could specify a smaller area in the source image to draw, so you end up with a cropped image.

The first image is an example of image cropping, he took a small chunk of the original image by using sx,sy that defined a smaller area than the entire image.




It's funny. I took that JavaWorld logo and performed the same operation for image#1, and I ended up with a totally different image. Appearently that example is plain wrong, and that's what got me confused, since I assumed it was correct! :\

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Eli Delventhal
« League of Dukes »

JGO Kernel


Medals: 39
Projects: 12


Game Engineer


« Reply #3 - Posted 2005-11-02 00:20:35 »

Yeah, when I was learning Java2D I actually used the same example and also got confused. Basically the first values tell how much of the actual image you will draw, then the last values specify where it is drawn, as well as width, height, flipping, etc.

The different drawImages you can do:

drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
          Draws the image at (x,y), but transparent piexels are filled with bgcolor.
drawImage(Image img, int x, int y, ImageObserver observer)
         Simply draws the image at (x,y)
drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
          Draws the image at (x,y) with resized to width and height dimensions and transparency filled in with bgcolor.
drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
          My favorite one: it draws the image at (x,y) and resizes it to width by height
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
          The most powerful one. Does what I said below, but transparent pixels are filled with bgcolor
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
          Will offset sx1,sy1 from the top left corner of the source and sx2-sx1 width by sy2-sy1 height and then draw that to (dx1,dy1) dx2-dx1 width by dy2-dy1 height.

Hopefully that makes sense.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (76 views)
2013-05-17 21:29:12

alaslipknot (87 views)
2013-05-16 21:24:48

gouessej (117 views)
2013-05-16 00:53:38

gouessej (112 views)
2013-05-16 00:17:58

theagentd (123 views)
2013-05-15 15:01:13

theagentd (112 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (178 views)
2013-05-12 17:10:36

kutucuk (177 views)
2013-05-12 15:36:09

UnluckyDevil (185 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.146 seconds with 20 queries.