mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2024-11-15 06:35:11 +01:00
Diverses modifications
This commit is contained in:
parent
f3510b1d3f
commit
f967564107
@ -1,5 +1,6 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@ -43,12 +44,51 @@ public class ImageRenderer extends Thread
|
||||
try
|
||||
{
|
||||
imgSrc = ImageIO.read(URI.create(URL).toURL().openStream());
|
||||
img = new Poster(imgSrc);
|
||||
int width = imgSrc.getWidth();
|
||||
int height = imgSrc.getHeight();
|
||||
|
||||
// Fonction qui cherche le multiple de 128 le plus proche
|
||||
// de la hauteur / largeur de l'image
|
||||
int tmpW = 0, tmpH = 0;
|
||||
int i = 1;
|
||||
while (tmpW < width)
|
||||
{
|
||||
|
||||
tmpW = i * 128;
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (tmpH < height)
|
||||
{
|
||||
|
||||
tmpH = i * 128;
|
||||
i++;
|
||||
}
|
||||
|
||||
// On crée un "canvas" = une image vide qui a une taille multiple de 128
|
||||
// dans laquelle on dessinera l'image téléchargées
|
||||
BufferedImage canvas = new BufferedImage(tmpW, tmpH, BufferedImage.TYPE_INT_ARGB);
|
||||
// On récupère l'objet Grapics2D, servant à dessiner dans notre canvas
|
||||
Graphics2D graph = canvas.createGraphics();
|
||||
|
||||
// Variable servant à cadrer l'image
|
||||
int centerX = 0, centerY = 0;
|
||||
centerX = (tmpW - imgSrc.getWidth()) / 2;
|
||||
centerY = (tmpH - imgSrc.getHeight()) / 2;
|
||||
//On déplace le point d'origine de graph afin que l'image soit dessinée au milieu du canvas
|
||||
graph.translate(centerX, centerY);
|
||||
//graph.rotate(45);
|
||||
// on dessine l'image dans le canvas
|
||||
graph.drawImage(imgSrc, null, null);
|
||||
// on crée un Poster à partir de notre canvas
|
||||
img = new Poster(canvas);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
erreur = true;
|
||||
}
|
||||
|
||||
estPrete = true;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user