Foros del Web » Programación para mayores de 30 ;) » Java »

[DUDA] g.drawImage() 10 argumentos

Estas en el tema de [DUDA] g.drawImage() 10 argumentos en el foro de Java en Foros del Web. Pues eso, que estoy dándole vueltas y no pillo como van los argumentos. Necesito el constructor de 10 argumentos. Mi idea es usar un tileset. ...
  #1 (permalink)  
Antiguo 22/07/2010, 17:43
Avatar de Rido  
Fecha de Ingreso: septiembre-2009
Mensajes: 5
Antigüedad: 14 años, 7 meses
Puntos: 0
[DUDA] g.drawImage() 10 argumentos

Pues eso, que estoy dándole vueltas y no pillo como van los argumentos. Necesito el constructor de 10 argumentos. Mi idea es usar un tileset. No quiero que me digáis cómo se hace, digo que me digáis qué es cada argumento. El resto ya me lo apaño yo solito o lo intento.

He visto que pone en los argumentos dx1, dy1, sx1, sy1 etc pero no sé qué carajo quiere decir. Sólo sé que el primero es una variable image con la imagen y el último el observador. Pero el resto...

Un saludo.
  #2 (permalink)  
Antiguo 23/07/2010, 09:25
Avatar de chuidiang
Colaborador
 
Fecha de Ingreso: octubre-2004
Mensajes: 3.774
Antigüedad: 19 años, 6 meses
Puntos: 454
Respuesta: [DUDA] g.drawImage() 10 argumentos

En al API te los cuenta

http://download.oracle.com/docs/cd/E.../Graphics.html

Se bueno.
__________________
Apuntes Java
Wiki de Programación
  #3 (permalink)  
Antiguo 23/07/2010, 16:48
Avatar de Rido  
Fecha de Ingreso: septiembre-2009
Mensajes: 5
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: [DUDA] g.drawImage() 10 argumentos

La API no me soluciona mucho ya que no sé qué quiere decir dx1, dx2, dy1, dy2, sx1, sx2, etc.

Igualmente creo que probando y probando logré hallar la solución. Pongo aquí la función y lo que creo que significan los argumentos:

g.drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)

- img: La imagen, no hay mucho que decir de esto.

- dx1: Es el píxel a partir del cual vamos a empezar a dibujar la imagen. Si pones 0, empezamos dibujando desde la parte izquierda de la imagen. Ojo, digo imagen, del dibujo que se quiere graficar, no de la ventana.

- dy1: Lo mismo pero en el eje de ordenada.

- dx2: Es hasta qué píxel de la imagen queremos dibujar. Si dx1 == 5 y dx2 == 10 pues dibujaremos a partir del píxel 5 en el eje de abcisa hasta el punto 10.

- dy2: Lo mismo que dx2 pero con el eje de ordenada.

- sx1: Bueno, tanto sx1 como sy1 son los píxeles a partir de los cuales vamos a empezar a graficar en nuestra ventana. sx2 y sy2 será hasta los píxeles que lleguemos graficando. Es como lo que puse antes pero esta vez en vez de referirnos a la imagen nos referimos a la ventana en la que vamos a dibujar la imagen.

- observer: Se refiere al observador, como es evidente. Si alguien quiere usar esto y no sabe lo que es que ponga this y punto. Yo no sé qué más a parte de this o null podría poner ni en qué podría cambiar ya que no he usado otra cosa.

Bueno, si alguien ve algún error en lo que puse que no dude en contestar con una corrección. Trastearé un poco más y si veo que no es así vuelvo y corrijo. Gracias a la persona que gastó su tiempo en responderme, muchas gracias.

Un saludo.
  #4 (permalink)  
Antiguo 23/07/2010, 21:44
Avatar de chuidiang
Colaborador
 
Fecha de Ingreso: octubre-2004
Mensajes: 3.774
Antigüedad: 19 años, 6 meses
Puntos: 454
Respuesta: [DUDA] g.drawImage() 10 argumentos

Copiado de la API

"iDraws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.
Transparent pixels are drawn in the specified background color. This operation is equivalent to filling a rectangle of the width and height of the specified image with the given color and then drawing the image on top of it, but possibly more efficient.

This method returns immediately in all cases, even if the image area to be drawn has not yet been scaled, dithered, and converted for the current output device. If the current output representation is not yet complete then drawImage returns false. As more of the image becomes available, the process that loads the image notifies the specified image observer.

This method always uses the unscaled version of the image to render the scaled rectangle and performs the required scaling on the fly. It does not use a cached, scaled version of the image for this operation. Scaling of the image from source to destination is performed such that the first coordinate of the source rectangle is mapped to the first coordinate of the destination rectangle, and the second source coordinate is mapped to the second destination coordinate. The subimage is scaled and flipped as needed to preserve those mappings.

Parameters:
img - the specified image to be drawn. This method does nothing if img is null.
dx1 - the x coordinate of the first corner of the destination rectangle.
dy1 - the y coordinate of the first corner of the destination rectangle.
dx2 - the x coordinate of the second corner of the destination rectangle.
dy2 - the y coordinate of the second corner of the destination rectangle.
sx1 - the x coordinate of the first corner of the source rectangle.
sy1 - the y coordinate of the first corner of the source rectangle.
sx2 - the x coordinate of the second corner of the source rectangle.
sy2 - the y coordinate of the second corner of the source rectangle.
bgcolor - the background color to paint under the non-opaque portions of the image.
observer - object to be notified as more of the image is scaled and converted.
"

La explicación es bastante detallada y dice exactamente lo que has puesto tú.

Se bueno.
__________________
Apuntes Java
Wiki de Programación
  #5 (permalink)  
Antiguo 24/07/2010, 08:20
Avatar de Rido  
Fecha de Ingreso: septiembre-2009
Mensajes: 5
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: [DUDA] g.drawImage() 10 argumentos

Hostias eso sí que no lo había visto. Genial y muchas gracias de nuevo, pueden dar el tema por cerrado. Mil gracias!

Etiquetas: argumentos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:20.