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
TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Arnault Nouvel et Antoine Dongois Le processus à prendre : Apprendre (découvrir la plateforme) Préparer (documenter l'historique et choisir la méthode de MAJ) Test (Test de MAJ) Implémenter (Effectuer la MAJ) Valid...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOURTECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOUR par ROMELARD Fabrice
Après un retour sur l'histoire des TechDays de Paris et le fait que ce soit le plus gros event MS au monde (du fait de sa gratuité), le président de MS France (Eric Boustoullier) a fait une présentation de la vision Microsoft pour les années à venir...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|