Loupe

Loupe - Java - Programmation

Marsh Posté le 31-07-2003 à 15:11:48    

Quelqu'un sait-il si il existe un composant qui permet de zoomer sur un graphique ????
 
Ca me parait impossible a moins que quelqu'un l'ait deja fait.

Reply

Marsh Posté le 31-07-2003 à 15:11:48   

Reply

Marsh Posté le 31-07-2003 à 17:29:59    

zizou39 a écrit :

Quelqu'un sait-il si il existe un composant qui permet de zoomer sur un graphique ????
 
Ca me parait impossible a moins que quelqu'un l'ait deja fait.


Y a une contradiction là, non ?  


---------------
Gérez votre collection de BD en ligne ! ---- Electro-jazzy song ---- Dazie Mae - jazzy/bluesy/cabaret et plus si affinité
Reply

Marsh Posté le 31-07-2003 à 17:31:46    

qqun connait un composant qui fait tout, genre que j'ai qu'à l'appeller  :pfff:


---------------
Just because you feel good does not make you right
Reply

Marsh Posté le 31-07-2003 à 17:36:31    

DarkLord a écrit :

qqun connait un composant qui fait tout, genre que j'ai qu'à l'appeller  :pfff:  


Mouais, surtout que ça me parait pas trop compliquer à faire.
Une image, c'est fait de pixel.
Pour zoomer sur une zone, il suffit donc de récupérer les pixel de cette zone, et pour chaque pixel de la  zone, tu crée par exemple un carré de pixel de la même couleur dans une autre image. En gros, c'est le principeque j'emploierai.


---------------
Gérez votre collection de BD en ligne ! ---- Electro-jazzy song ---- Dazie Mae - jazzy/bluesy/cabaret et plus si affinité
Reply

Marsh Posté le 31-07-2003 à 18:03:42    

dans java presque tout existe deja
 
http://developer.java.sun.com/deve [...] ifier.java
en fait il s'agit d'un composant reutilisable qui se contente d'appeler l'operateur "scale" de JAI
 
tu peux telecharger le JAI_TUTOR, dont ce widget fait parti, c'est un recueil d'exemples presentes dans une interface graphique.
il y a des facons de faire qui ont changes, mais dans l'ensemble c'est encore bon.
 
Si tu connais pas ImageIO profites aussi pour faire des recherches , que ce soit pour l'utiliser ou pour l'etendre c'est incontournable :)

Reply

Marsh Posté le 01-08-2003 à 14:27:27    

Je connais rien au applet.
J'ai les sources qu'il me faut mais c'est pour applet.
Comment dois-je faire pour utiliser ce code dans mon application ? Que dois-je transformer. Voici le code des deux classes :
 

Citation :


import java.applet.Applet;
import java.awt.*;
import java.io.PrintStream;
 
public class vLens extends Applet
    implements Cloneable
{
 
    void drawFineVert()
    {
        int i = m_size / (smallFac + 1);
        int j = i;
        for(int k = m_size - j; k > 0;)
        {
            gbuf.copyArea(xPos - xCirc[k + j], yPos - k, (xCirc[k + j] << 1) + pmag, smallFac + 1, 0, -j);
            gbuf.copyArea(xPos - xCirc[k + j], yPos + k, (xCirc[k + j] << 1) + pmag, smallFac + 1, 0, j);
            k -= smallFac;
            j--;
        }
 
    }
 
    public boolean mouseEnter(Event event, int i, int j)
    {
        showLens();
        return true;
    }
 
    public void popup()
    {
        try
        {
            (new vpopIt(width, height)).add("Center", add((Component)clone()));
            return;
        }
        catch(CloneNotSupportedException _ex)
        {
            System.err.println("Popup Failure!" );
        }
    }
 
    public boolean mouseExit(Event event, int i, int j)
    {
        hideLens();
        return true;
    }
 
    void GetParameters()
    {
        String s;
        if((s = getParameter("image" )) != null)
            image = s;
        if((s = getParameter("diameter" )) != null)
            radius = Integer.parseInt(s) / 2;
        if((s = getParameter("power" )) != null)
            pmag = mag = Integer.parseInt(s);
        if((s = getParameter("lopower" )) != null)
            smallFac = 9 - Integer.parseInt(s);
        if((s = getParameter("shape" )) != null)
            arrayType = Integer.parseInt(s);
        if((s = getParameter("frame" )) != null)
            rim = Integer.parseInt(s) != 0;
        if(pmag == 0)
            pmag = mag = 1;
        if(pmag < 0)
            pmag = -pmag;
        if(pmag > 2)
        {
            smallFac = 1;
            return;
        } else
        {
            smallFac = 9;
            return;
        }
    }
 
    public void paint(Graphics g)
    {
        drawImage();
        g.drawImage(buf, 0, 0, this);
    }
 
    void drawvLensHorz()
    {
        int i = pmag;
        for(int j = m_size - 1; j > 0; j--)
        {
            gbuf.copyArea(xPos - j, yPos - xCirc[j] * i, pmag, ((xCirc[j] << 1) + 1) * pmag, j * (1 - mag), 0);
            gbuf.copyArea(xPos + j, yPos - xCirc[j] * i, pmag, ((xCirc[j] << 1) + 1) * pmag, j * (mag - 1), 0);
        }
 
    }
 
    void drawFineHorz()
    {
        int i = m_size / (smallFac + 1);
        int j = pmag;
        int k = i;
        for(int l = m_size - k; l > 0;)
        {
            gbuf.copyArea(xPos - l, yPos - xCirc[l + k] * j, smallFac + 1, ((xCirc[l + k] << 1) + 1) * pmag, -k, 0);
            gbuf.copyArea(xPos + l, yPos - xCirc[l + k] * j, smallFac + 1, ((xCirc[l + k] << 1) + 1) * pmag, k, 0);
            l -= smallFac;
            k--;
        }
 
    }
 
    public boolean mouseUp(Event event, int i, int j)
    {
        xonly = yonly = false;
        setCursor(1);
        return true;
    }
 
    void drawRim()
    {
        int i;
        switch(arrayType)
        {
        case 0: // '\0'
            gbuf.drawOval(xPos - m_size, yPos - m_size, m_size * 2, m_size * 2);
            gbuf.drawOval(xPos - m_size, yPos - m_size - 1, m_size * 2, m_size * 2);
            gbuf.drawOval(xPos - m_size, (yPos - m_size) + 1, m_size * 2, m_size * 2);
            gbuf.drawOval(xPos - m_size - 1, yPos - m_size, m_size * 2, m_size * 2);
            gbuf.drawOval((xPos - m_size) + 1, yPos - m_size, m_size * 2, m_size * 2);
            return;
 
        case 2: // '\002'
            gbuf.drawRect(xPos - m_size - 1, yPos - m_size - 1, m_size * 2 + 2, m_size * 2 + 2);
            gbuf.drawRect(xPos - m_size, yPos - m_size, m_size * 2, m_size * 2);
            return;
 
        case 1: // '\001'
        default:
            i = m_size;
            break;
        }
        for(; i > 0; i--)
        {
            gbuf.drawLine(xPos - xCirc[i], yPos - i, xPos - xCirc[i - 1], yPos - i);
            gbuf.drawLine(xPos - xCirc[i], yPos + i, xPos - xCirc[i - 1], yPos + i);
            gbuf.drawLine(xPos + xCirc[i], yPos - i, xPos + xCirc[i - 1], yPos - i);
            gbuf.drawLine(xPos + xCirc[i], yPos + i, xPos + xCirc[i - 1], yPos + i);
        }
 
    }
 
    void drawSlowVert()
    {
        int i = 128;
        int j;
        for(j = 7; (i & pmag) == 0; j--)
            i >>= 1;
 
        int k = pmag - i;
        for(int l = m_size - 1; l >= 0; l--)
        {
            gbuf.copyArea(xPos - xCirc[l], yPos - l, (xCirc[l] << 1) + pmag, 1, 0, l * (1 - mag));
            gbuf.copyArea(xPos - xCirc[l], yPos + l, (xCirc[l] << 1) + pmag, 1, 0, l * (mag - 1));
            for(int i1 = 0; i1 < j; i1++)
            {
                gbuf.copyArea(xPos - xCirc[l], yPos - l * mag, (xCirc[l] << 1) + pmag, 1 << i1, 0, 1 << i1);
                gbuf.copyArea(xPos - xCirc[l], yPos + l * mag, (xCirc[l] << 1) + pmag, 1 << i1, 0, 1 << i1);
            }
 
            if(k > 0)
            {
                gbuf.copyArea(xPos - xCirc[l], yPos - l * mag, (xCirc[l] << 1) + pmag, k, 0, 1 << j);
                gbuf.copyArea(xPos - xCirc[l], yPos + l * mag, (xCirc[l] << 1) + pmag, k, 0, 1 << j);
            }
        }
 
    }
 
    public vLens()
    {
        radius = 100;
        mag = 2;
        smallFac = 9;
        pmag = 2;
        xPos = 60;
        yPos = 20;
    }
 
    public void update(Graphics g)
    {
        paint(g);
    }
 
    boolean imageloading()
    {
        if(iimage == null)
            return true;
        return iimage.getWidth(this) < 0 || iimage.getHeight(this) < 0;
    }
 
    public void start()
    {
        setCursor(1);
        m_size = radius / mag;
        makeCircleArray();
        iimage = getImage(getDocumentBase(), image);
        try
        {
            for(; imageloading(); repaint())
                Thread.sleep(100L);
 
            return;
        }
        catch(InterruptedException _ex)
        {
            stop();
        }
    }
 
    public final String getAppletInfo()
    {
        return "Name: uniform lens\r\nAuthor: Xavier Potier\r\n";
    }
 
    public void showLens()
    {
        hidden = false;
        repaint();
    }
 
    public boolean mouseDown(Event event, int i, int j)
    {
        if(event.metaDown())
        {
            if(++arrayType > 4)
                arrayType = 0;
            makeCircleArray();
        } else
        if(event.shiftDown())
            hidden = !hidden;
        else
        if(event.controlDown())
            popup();
        repaint();
        return true;
    }
 
    void drawImage()
    {
        if(iimage != null)
        {
            gbuf.drawImage(iimage, 0, 0, null);
        } else
        {
            gbuf.setColor(Color.white);
            gbuf.fillRect(0, 0, width, height);
            gbuf.setColor(Color.black);
            gbuf.drawString("loading, please wait...", 0, height - 20);
        }
        if(!hidden)
        {
            gbuf.setColor(Color.white);
            gbuf.fillRect(0, 0, 200, 60);
            gbuf.setColor(Color.blue);
            gbuf.setFont(new Font(gbuf.getFont().getName(), 0, 20));
            gbuf.drawString("unregistered", 30, 30);
            if(pmag > 3)
            {
                drawSlowVert();
                drawSlowHorz();
                return;
            }
            if(pmag > 1)
            {
                drawvLensVert();
                drawvLensHorz();
                return;
            }
            drawFineVert();
            drawFineHorz();
        }
    }
 
    void makeCircleArray()
    {
        xCirc = new int[m_size + 1];
        switch(arrayType)
        {
        case 0: // '\0'
            for(int i = 0; i < m_size; i++)
                xCirc[i] = (int)Math.sqrt(m_size * m_size - i * i);
 
            xCirc[0] = xCirc[1];
            xCirc[m_size] = 0;
            return;
 
        case 1: // '\001'
            for(int j = 0; j < m_size / 2 + 1; j++)
            {
                xCirc[j] = m_size - 1;
                xCirc[j + m_size / 2] = (int)Math.sqrt((m_size * m_size) / 4 - j * j) + m_size / 2;
            }
 
            xCirc[0] = xCirc[1];
            xCirc[m_size] = 0;
            return;
 
        case 2: // '\002'
            for(int k = 0; k < m_size; k++)
                xCirc[k] = m_size - 1;
 
            return;
 
        case 3: // '\003'
            for(int l = 0; l < m_size; l++)
                xCirc[m_size - 1 - l] = l;
 
            return;
 
        case 4: // '\004'
            for(int i1 = 0; i1 < m_size; i1++)
                xCirc[m_size - 1 - i1] = m_size - (int)Math.sqrt(m_size * m_size - i1 * i1);
 
            return;
        }
    }
 
    public void hideLens()
    {
        hidden = true;
        repaint();
    }
 
    public void init()
    {
        GetParameters();
        buf = createImage(width = size().width, height = size().height);
        gbuf = buf.getGraphics();
    }
 
    void drawSlowHorz()
    {
        int i = 128;
        int j;
        for(j = 7; (i & pmag) == 0; j--)
            i >>= 1;
 
        int k = pmag - i;
        for(int l = m_size - 1; l >= 0; l--)
        {
            gbuf.copyArea(xPos - l, yPos - xCirc[l] * pmag, 1, ((xCirc[l] << 1) + 1) * pmag, l * (1 - mag), 0);
            gbuf.copyArea(xPos + l, yPos - xCirc[l] * pmag, 1, ((xCirc[l] << 1) + 1) * pmag, l * (mag - 1), 0);
            for(int i1 = 0; i1 < j; i1++)
            {
                gbuf.copyArea(xPos - l * mag, yPos - xCirc[l] * pmag, 1 << i1, ((xCirc[l] << 1) + 1) * pmag, 1 << i1, 0);
                gbuf.copyArea(xPos + l * mag, yPos - xCirc[l] * pmag, 1 << i1, ((xCirc[l] << 1) + 1) * pmag, 1 << i1, 0);
            }
 
            if(k > 0)
            {
                gbuf.copyArea(xPos - l * mag, yPos - xCirc[l] * pmag, k, ((xCirc[l] << 1) + 1) * pmag, 1 << j, 0);
                gbuf.copyArea(xPos + l * mag, yPos - xCirc[l] * pmag, k, ((xCirc[l] << 1) + 1) * pmag, 1 << j, 0);
            }
        }
 
    }
 
    public boolean mouseDrag(Event event, int i, int j)
    {
        if(!xonly)
        {
            if(j - yPos > 0)
                ymov++;
            else
            if(j - yPos < 0)
                ymov--;
            if(ymov >= 4 || ymov <= -4)
            {
                yonly = true;
                setCursor(8);
                if(pmag == 1)
                {
                    smallFac += ymov >> 2;
                    if(smallFac == 0 || smallFac == 11)
                    {
                        smallFac -= ymov >> 2;
                        mag += -ymov >> 2;
                    }
                } else
                {
                    mag += -ymov >> 2;
                }
                if(mag > 255)
                    mag &= 0xff;
                if(mag == 0)
                    mag += -ymov >> 2;
                pmag = Math.abs(mag);
                ymov = 0;
                m_size = radius / pmag;
                makeCircleArray();
            }
        }
        if(!yonly)
        {
            if(i - xPos > 0)
                xmov++;
            else
            if(i - xPos < 0)
                xmov--;
            if(xmov >= 4 || xmov <= -4)
            {
                xonly = true;
                setCursor(11);
                radius += xmov << 1;
                if(radius < 0)
                    radius = 0;
                xmov = 0;
                m_size = radius / pmag;
                makeCircleArray();
            }
        }
        xPos = i;
        yPos = j;
        repaint();
        return true;
    }
 
    public void setCursor(int i)
    {
        try
        {
            ((Frame)getParent()).setCursor(i);
            return;
        }
        catch(ClassCastException classcastexception)
        {
            System.err.println("E class cast: " + classcastexception);
        }
    }
 
    void drawvLensVert()
    {
        for(int i = m_size - 1; i > 0; i--)
        {
            gbuf.copyArea(xPos - xCirc[i], yPos - i, (xCirc[i] << 1) + pmag, pmag, 0, i * (1 - mag));
            gbuf.copyArea(xPos - xCirc[i], yPos + i, (xCirc[i] << 1) + pmag, pmag, 0, i * (mag - 1));
        }
 
    }
 
    public boolean mouseMove(Event event, int i, int j)
    {
        xPos = i;
        yPos = j;
        repaint();
        return true;
    }
 
    String image;
    Image iimage;
    Image buf;
    Graphics gbuf;
    boolean xonly;
    boolean yonly;
    boolean rim;
    boolean isBusy;
    boolean hidden;
    int width;
    int height;
    int radius;
    int mag;
    int smallFac;
    int pmag;
    int arrayType;
    int xPos;
    int yPos;
    int ymov;
    int xmov;
    int m_size;
    int xCirc[];
}


 
et l'autre  

Citation :


import java.awt.*;
 
class vpopIt extends Frame
{
 
    public boolean handleEvent(Event event)
    {
        if(event.id == 201)
            dispose();
        return true;
    }
 
    public vpopIt(int i, int j)
    {
        super("Image with Lens - v-era.com" );
        setCursor(1);
        show();
        hide();
        resize(insets().left + insets().right + i, insets().top + insets().bottom + j);
        show();
    }


 
C'est un peu je suis des

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed