Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 1765 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Posted 2005-10-28 22: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-28 22: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 Wizard


Medals: 50
Projects: 4


I always win!


« Reply #2 - Posted 2005-10-29 01: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!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #3 - Posted 2005-11-01 23: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.

 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (12 views)
2014-08-28 18:26:30

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (37 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (29 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (28 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!