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
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
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
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 112896 [ par salhiamina ]
Salut j'ai un petit souci avec mon bout de code. j'essai d'écrire le code java pour segmenter une image avec l'approche croissance de région. quand j'
quelle classe pour la segmentation par croissance de region [ par salhiamina ]
salut tous le monde pour travailler sur la segmentation d'une image mammographie par croissance de région sur java (eclipse comme envéronement de deve
problème d'affichage d'une image bmp [ par rayhana1 ]
salut, j'ai cherché comment afficher une image bmp sous java, donc j'ai utilisé ça: [b]label.setIcon(new ImageIcon("images/"+name+".bmp"));[/b] ça
the import javax.media.jai cannot be resolved [ par salhiamina ]
Bonjour à tous J'ai récemment installé Eclipse sur ma machine Windows XP, avec jdk1.6.0_11. quand j'ai fait un teste avec un petit code que j'ai téléc
|
Derniers Blogs
PRATIQUE DE SILVERLIGHT PAR ERIC AMBROSIPRATIQUE DE SILVERLIGHT PAR ERIC AMBROSI par MPOWARE
Je viens de finir la lecture du dernier livre d'
Eric Ambrosi
éditions PEARSON
Son livre donne une approche pratique de Silverlight qui sera aussi bien comprise par le développeur que par le designeur.
Tous les aspects du développement RIA sont abor...
Cliquez pour lire la suite de l'article par MPOWARE APPRENDRE à DéVELOPPER POUR LES MOBILES AVEC LA NOUVELLE GéNéRATION .NETAPPRENDRE à DéVELOPPER POUR LES MOBILES AVEC LA NOUVELLE GéNéRATION .NET par odewit
2 déclinaisons de Silverlight et 2 déclinaisons de Mono permettent dorénavant (ou permettront prochainement) de développer des applications .NET mobiles pour les principales plates-formes du marché :
Silverlight pour Symbian, basé sur Silverlight 2...
Cliquez pour lire la suite de l'article par odewit ZUNE : NOUVELLE VERSION DU ZUNE SOFTWARE - V 4.2ZUNE : NOUVELLE VERSION DU ZUNE SOFTWARE - V 4.2 par ROMELARD Fabrice
Avec la dernière génération du lecteur MP3 de Microsoft, le ZUNE HD, Microsoft a publié une nouvelle version du logiciel pour PC. Ainsi, je me suis décidé à installer celle-ci sur mon Tablet PC ACER, comme toujours le logiciel est donc tél...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice L'INTERFACE NATURELLE DE WINDOWS PHONE 7 SERIESL'INTERFACE NATURELLE DE WINDOWS PHONE 7 SERIES par odewit
La tendance est aux interfaces naturelles (NUI), et le keynote de Bill Buxton au MIX l'a bien souligné.
La charte graphique et ergonomique de Windows Phone 7 a donc été entièrement repensée en vue d'obtenir un maximum d'efficacité sur ce point. En re...
Cliquez pour lire la suite de l'article par odewit
Forum
PARALLELISATIONPARALLELISATION par infogoss
Cliquez pour lire la suite par infogoss
Logiciels
Academy System (10.9.4.0)ACADEMY SYSTEM (10.9.4.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods
|