begin process at 2010 02 09 20:55:51
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Java2D

 > 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

Note :
Aucune note
Catégorie :Java2D Classé sous :display, image, jai, jiio, jcsp Niveau :Initié Date de création :31/05/2007 Date de mise à jour :11/07/2007 21:36:37 Vu / téléchargé :8 690 / 770

Auteur : broumbroum

Ecrire un message privé
Site perso
Commentaire sur cette source (5)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
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

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  • jcspclasses.jarTélécharger ce fichier [Réservé aux membres club]204 390 octets

Télécharger le zip


 Historique

01 juin 2007 00:12:33 :
div contructors
11 juillet 2007 21:36:37 :
scale fix avec floats

 Sources du même auteur

Source avec Zip Source avec une capture RENDERING SCENE POUR JEU 2D TOUTE PLATEFORME (JAI/JIIO)
CONSOLE STANDARD IMPLEMENTABLE AVEC UN INPUTLOGLISTENER
Source avec Zip Source avec une capture IMAGE MULTI CONVERTER
Source avec Zip Source avec une capture SPRITES CACHE MANAGER POUR GESTION MÉMOIRE DE GRAND NOMBRE D...
Source avec Zip Source avec une capture ANIMATIONS JAVA ADVANCED IMAGING (AVEC TAMPON MÉMOIRE)

 Sources de la même categorie

AFFICHER UNE ÉTOILE AVEC JAVA2D par 2mohamed2
TEXTE AVEC OMBRE par 2mohamed2
Source avec Zip Source avec une capture JBOXIKON PORTAGE DE BOXIKON par ulm950
Source avec Zip Source avec une capture AQUARIUM 2D AVEC DOUBLE-BUFFERING ET EN UTILISANT UNIQUEMENT... par Cornellus1985
Source avec Zip Source avec une capture JPANELTEXTEDEFILANT : FAIRE DEFILER DU TEXTE (PLUSIEURES MAN... par loloof64

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture [CONCOURS ANDROID] PHOTOTHÈQUE par julienchauveau
Source avec Zip Source avec une capture RENDERING SCENE POUR JEU 2D TOUTE PLATEFORME (JAI/JIIO) par broumbroum
Source avec Zip Source avec une capture IMAGE MULTI CONVERTER par broumbroum
Source avec une capture TÉLÉCHARGEMENT D'IMAGES (POCHETTES CD, DVD, LIVRES...) SUR I... par dufour137
FAIRE DEFILER UNE IMAGE par Nic.C

Commentaires et avis

Commentaire de sheorogath le 01/06/2007 19:47:12 administrateur CS

le package est il de toi ?
ou alors ta source c''est juste ce qu'il y a dans source lol

Commentaire de broumbroum le 01/06/2007 21:50:44

tout est de ma conception, à part les "binairies" de JCSP venant d'étudiants aux USA.

Commentaire de jaoued zahraoui le 04/06/2007 17:13:31

bonjour,

j'arrive pas a l'utiliser, j'ai importer le package JAI mais il me manque toujours celui qui contient com.sun.media.imageio.stream.FileChannelImageInputStream.
aidez moi svp.

Commentaire de broumbroum le 04/06/2007 20:51:27

il te manque JAIIO Java Advanced Imaging I/O en supplement de JAI.

Commentaire de jaoued zahraoui le 05/06/2007 09:12:39

pour ceux qui ont du mal a trouver les librairies comme moi je met les liens :
https://jai.dev.java.net/binary-builds.html
https://jai-imageio.dev.java.net/binary-builds.html

comme c'est des librairies natives il faut telecharger celles corespondant au systeme d'exploitation que vous utilisé. une foi installé les jar se retrouvent dans le dossier lib/ext de votre jre.

 Ajouter un commentaire


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


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,655 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales