Accueil > > > AFFICHEUR D'IMAGE ACCÉLÉRÉ JAVA ADVANCED IMAGING 1.1
AFFICHEUR D'IMAGE ACCÉLÉRÉ JAVA ADVANCED IMAGING 1.1
Information sur la source
Description
Cet afficheur est utilisé pour obtenir un affichage personnalisé de n'importe quel image supportée avec JAI/JIIO 1.1. Il s'implémente aisément dans n'importe quelle application awt/swing. Il dispose d'une capacité de redimensionnement avanée grace aux "transforms" Java2D. C'est un composant JCSP actif. b23:production GNU/GPL package installer du projet sf3jswing. http://sourceforge.net/projects/sf3jswi ng/
Source
- package installer;/*
- * Display.java
- *
- * Created on 24 novembre 2006, 05:37
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
- import com.sun.media.imageio.stream.FileChannelImageInputStream;
- import java.awt.AlphaComposite;
- import java.awt.Color;
- import java.awt.Composite;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Rectangle;
- import java.awt.geom.AffineTransform;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- import java.lang.ref.PhantomReference;
- import java.lang.ref.Reference;
- import java.lang.ref.ReferenceQueue;
- import java.net.URISyntaxException;
- import java.net.URL;
- import javax.imageio.ImageIO;
- import javax.swing.JComponent;
- import jcsp.lang.CSProcess;
- import jcsp.lang.Parallel;
-
- /**
- * This class allows to display an Image in a component that can be added to any Container.
- * Component will be scaled to Image size to fit it.
- * It is synchronized on the component with the MediaTracker.
- *@see #mt
- * @see Image
- *@see MediaTracker
- * @author www.b23prodtm.com
- */
- public class Display extends JComponent {
- /** the MediaTracker to manage full loading of the image data */
- private MediaTracker mt;
- /** the image to display */
- private Image display;
- /** phantom ref to image */
- private PhantomReference phantomImage;
- /** Transform instance to scale the image */
- private AffineTransform tx;
- /** background color
- * @default Color.LIGHT_GRAY */
- private Color background = Color.LIGHT_GRAY;
- /***/
- private Rectangle originalBox;
- /***/
- private BufferedImage bgImg;
- /***/
- private ReferenceQueue<? extends Reference> refQueue = new ReferenceQueue<Reference>();
-
- /***/
- public Display(String filename, AffineTransform tx) throws IOException {
- this(ImageIO.read(
- new FileChannelImageInputStream(
- new RandomAccessFile(filename, "rws").getChannel()
- )), tx);
- }
-
- /***/
- public Display(URL filename, AffineTransform tx) throws IOException, URISyntaxException {
- this(ImageIO.read(
- new FileChannelImageInputStream(
- new RandomAccessFile(new File(filename.toURI()), "rws").getChannel()
- )), tx);
- }
-
- /***/
- public Display(String filename, AffineTransform tx, Dimension size) throws IOException {
- this(ImageIO.read(
- new FileChannelImageInputStream(
- new RandomAccessFile(filename, "rws").getChannel()
- )), tx, size);
- }
-
- /***/
- public Display(URL filename, AffineTransform tx, Dimension size) throws IOException, URISyntaxException {
- this(ImageIO.read(
- new FileChannelImageInputStream(
- new RandomAccessFile(new File(filename.toURI()), "rws").getChannel()
- )), tx, size);
- }
-
- /** the constructor of one Display
- * @param display the image to display
- * @param tx the transform to apply to the Display. if null, the component will fit the image size */
- public Display(Image display, AffineTransform tx) {
- super();
- phantomImage = new PhantomReference(display, refQueue);
- try {
- bgImg = ImageIO.read(getClass().getResourceAsStream("images/duke.gif"));
- mt = new MediaTracker(this);
- this.display = display;
- if(tx != null) {
- this.tx = tx;
- } else
- this.tx = AffineTransform.getScaleInstance(1.0, 1.0);
- originalBox = new Rectangle(0, 0, display.getWidth(this), display.getHeight(this));
- setPreferredSize(originalBox.getBounds().getSize());
- setSize(getPreferredSize());
- validate();
- repaint();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
-
- /** the constructor of one Display
- * @param display the image to display
- * @param tx the transform to apply to the Display. if null, the component will fit the image size */
- public Display(Image display, AffineTransform tx, Dimension size) {
- super();
- phantomImage = new PhantomReference(display, refQueue);
- try {
- bgImg = ImageIO.read(getClass().getResourceAsStream("images/duke.gif"));
- mt = new MediaTracker(this);
- this.display = display;
- if(tx != null) {
- this.tx = tx;
- } else
- this.tx = AffineTransform.getScaleInstance(1.0, 1.0);
- originalBox = new Rectangle(0, 0, display.getWidth(this), display.getHeight(this));
- setPreferredSize(size);
- setSize(getPreferredSize());
- repaint();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
-
- /***/
- public void finalize() {
- try {
- super.finalize();
- } catch (Throwable ex) {
- ex.printStackTrace();
- } finally {
- Reference ref;
- while((ref = refQueue.poll()) instanceof Reference) {
- ref.clear();
- }
- }
- }
-
- /** sets the background color
- * @param color the background color to use*/
- public void setBGColor(Color color) {
- background = color;
- }
-
- /** returns the image displayed in this component
- * @return the displayed picture*/
- public Image getPicture() {
- return display;
- }
-
- /***/
- public void setTX(AffineTransform tx) {
- this.tx = tx;
- }
-
- /***/
- public AffineTransform getTX() {
- return tx;
- }
-
- /** overriden to draw the image on the component graphics
- * @param g1 the Graphics instance*/
- public void paintComponent(Graphics g1) {
- Graphics2D g = (Graphics2D)g1;
- originalBox = new Rectangle(0, 0, display.getWidth(this), display.getHeight(this));
- Rectangle box = this.tx.createTransformedShape(new Rectangle(0, 0, getWidth(), getHeight())).getBounds();
- AffineTransform resizeTX = AffineTransform.getScaleInstance(
- ((double)((float)box.width)/((float)originalBox.width)),
- ((double)((float)box.height)/((float)originalBox.height))
- );
- g.setClip(box);
- g.setBackground(background);
- g.clearRect(box.x, box.y, box.width, box.height);
- Composite cps = g.getComposite();
- AffineTransform tx = AffineTransform.getScaleInstance(
- ((double)((float)box.width)/((float)bgImg.getWidth(this))),
- ((double)((float)box.height)/((float)bgImg.getWidth(this)))
- );
- mt.addImage(bgImg, bgImg.hashCode(), box.width, box.height);
- mt.addImage(display, hashCode(), box.width, box.height);
- try {
- mt.waitForAll();
- g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.33f));
- g.drawImage(bgImg, tx, this);
- g.setComposite(cps);
- g.drawImage(display, resizeTX, this);
- super.paintComponent(g);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
- }
- }
package installer;/*
* Display.java
*
* Created on 24 novembre 2006, 05:37
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import com.sun.media.imageio.stream.FileChannelImageInputStream;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.net.URISyntaxException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import jcsp.lang.CSProcess;
import jcsp.lang.Parallel;
/**
* This class allows to display an Image in a component that can be added to any Container.
* Component will be scaled to Image size to fit it.
* It is synchronized on the component with the MediaTracker.
*@see #mt
* @see Image
*@see MediaTracker
* @author www.b23prodtm.com
*/
public class Display extends JComponent {
/** the MediaTracker to manage full loading of the image data */
private MediaTracker mt;
/** the image to display */
private Image display;
/** phantom ref to image */
private PhantomReference phantomImage;
/** Transform instance to scale the image */
private AffineTransform tx;
/** background color
* @default Color.LIGHT_GRAY */
private Color background = Color.LIGHT_GRAY;
/***/
private Rectangle originalBox;
/***/
private BufferedImage bgImg;
/***/
private ReferenceQueue<? extends Reference> refQueue = new ReferenceQueue<Reference>();
/***/
public Display(String filename, AffineTransform tx) throws IOException {
this(ImageIO.read(
new FileChannelImageInputStream(
new RandomAccessFile(filename, "rws").getChannel()
)), tx);
}
/***/
public Display(URL filename, AffineTransform tx) throws IOException, URISyntaxException {
this(ImageIO.read(
new FileChannelImageInputStream(
new RandomAccessFile(new File(filename.toURI()), "rws").getChannel()
)), tx);
}
/***/
public Display(String filename, AffineTransform tx, Dimension size) throws IOException {
this(ImageIO.read(
new FileChannelImageInputStream(
new RandomAccessFile(filename, "rws").getChannel()
)), tx, size);
}
/***/
public Display(URL filename, AffineTransform tx, Dimension size) throws IOException, URISyntaxException {
this(ImageIO.read(
new FileChannelImageInputStream(
new RandomAccessFile(new File(filename.toURI()), "rws").getChannel()
)), tx, size);
}
/** the constructor of one Display
* @param display the image to display
* @param tx the transform to apply to the Display. if null, the component will fit the image size */
public Display(Image display, AffineTransform tx) {
super();
phantomImage = new PhantomReference(display, refQueue);
try {
bgImg = ImageIO.read(getClass().getResourceAsStream("images/duke.gif"));
mt = new MediaTracker(this);
this.display = display;
if(tx != null) {
this.tx = tx;
} else
this.tx = AffineTransform.getScaleInstance(1.0, 1.0);
originalBox = new Rectangle(0, 0, display.getWidth(this), display.getHeight(this));
setPreferredSize(originalBox.getBounds().getSize());
setSize(getPreferredSize());
validate();
repaint();
} catch (IOException ex) {
ex.printStackTrace();
}
}
/** the constructor of one Display
* @param display the image to display
* @param tx the transform to apply to the Display. if null, the component will fit the image size */
public Display(Image display, AffineTransform tx, Dimension size) {
super();
phantomImage = new PhantomReference(display, refQueue);
try {
bgImg = ImageIO.read(getClass().getResourceAsStream("images/duke.gif"));
mt = new MediaTracker(this);
this.display = display;
if(tx != null) {
this.tx = tx;
} else
this.tx = AffineTransform.getScaleInstance(1.0, 1.0);
originalBox = new Rectangle(0, 0, display.getWidth(this), display.getHeight(this));
setPreferredSize(size);
setSize(getPreferredSize());
repaint();
} catch (IOException ex) {
ex.printStackTrace();
}
}
/***/
public void finalize() {
try {
super.finalize();
} catch (Throwable ex) {
ex.printStackTrace();
} finally {
Reference ref;
while((ref = refQueue.poll()) instanceof Reference) {
ref.clear();
}
}
}
/** sets the background color
* @param color the background color to use*/
public void setBGColor(Color color) {
background = color;
}
/** returns the image displayed in this component
* @return the displayed picture*/
public Image getPicture() {
return display;
}
/***/
public void setTX(AffineTransform tx) {
this.tx = tx;
}
/***/
public AffineTransform getTX() {
return tx;
}
/** overriden to draw the image on the component graphics
* @param g1 the Graphics instance*/
public void paintComponent(Graphics g1) {
Graphics2D g = (Graphics2D)g1;
originalBox = new Rectangle(0, 0, display.getWidth(this), display.getHeight(this));
Rectangle box = this.tx.createTransformedShape(new Rectangle(0, 0, getWidth(), getHeight())).getBounds();
AffineTransform resizeTX = AffineTransform.getScaleInstance(
((double)((float)box.width)/((float)originalBox.width)),
((double)((float)box.height)/((float)originalBox.height))
);
g.setClip(box);
g.setBackground(background);
g.clearRect(box.x, box.y, box.width, box.height);
Composite cps = g.getComposite();
AffineTransform tx = AffineTransform.getScaleInstance(
((double)((float)box.width)/((float)bgImg.getWidth(this))),
((double)((float)box.height)/((float)bgImg.getWidth(this)))
);
mt.addImage(bgImg, bgImg.hashCode(), box.width, box.height);
mt.addImage(display, hashCode(), box.width, box.height);
try {
mt.waitForAll();
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.33f));
g.drawImage(bgImg, tx, this);
g.setComposite(cps);
g.drawImage(display, resizeTX, this);
super.paintComponent(g);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
Conclusion
Il y a une image de fond nommée images/duke.gif pour obtenir un fond personnalisé avec votre logo. Attention! le package JCSP doit être ajouté aux librairies de l'application pour compiler. Annexe: JCSPclasses.zip
L'application Image Multi-Converter Ant utilise cet afficheur dans le sélecteur de fichiers intégré. http://broumbroum84mirror3.ifrance.com/jn lp/demos/imc.jnlp
Historique
- 01 juin 2007 00:12:33 :
- div contructors
- 11 juillet 2007 21:36:37 :
- scale fix avec floats
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
JAI : raster et sharing [ par misterpatate ]
Salut à tous,Bon j'ai un petit problème depuis quelques semaines avec la JAI. ça a l'air surpuissant comme truc mais à doncdition de bien le faire mar
impression papier [ par Albator84 ]
salut,je cherche le moyen d'imprimer une image (sur papier). G importé mon image avec du JAI.et je crois ke la méthode pour imprimer kon on utilise du
image bmp [ par djaouida27 ]
salut!j'ai un problème d'affichage et d'envoie d'une image bmp!.jai trouver des aides mais toujours concernant les images JPG mais jai rien trouver po
JAI ( Java Advanced Imaging) et gradient. [ par noula27 ]
Bonjour, J'ai une image couleur que je apppliquer un gradient grace a deux masques comme suit: // chargement de l'image. PlanarImage im0 = (Pla
Translation d'une image avec l'API JAI [ par lyra88 ]
Bonjour, Je réalise un projet de recalage d'images sous java et je dois donc translater une image, pour cela j'utilise l'API JAI. J'ai donc écrit une
vidéo [ par LATIFA111 ]
j'ai besoin de votre aide. s'il vous plait . est ce qui' il ya quelqun qui peut me donner un code source en java qui permet de lire une séquence vidéo
jtabbedpane [ par safiajava ]
salut, dans mon projet j'ai plusieurs classe la classe principale(classMenu)avec deux panneux (pr afficher l'image avec son histograme)et afficheImage
repérage du position d'un point M(x,y) dans une image [ par hac2009 ]
Bonjour tout le monde, Je travail sur un Projet de Fin d'étude, mon sujet a pour but de: " Récupérer les coordonnées d'un défaut au niveau d'un
parcourir une image [ par hayo1 ]
svp qlq m'aider a parcourir une image en java ? de meme avec jrxml? je veux parcourir a chaque personne son propre photo en java ?de meme pour impri
Interpolation d'images [ par JM13nouveau ]
hello,J'ai une image à interpoler pour avoir une image de dimension 512x512, cette image est le produit de reconstruction d'images ( nbrimages et NP
|
Derniers Blogs
SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|