How to draw an image onto a canvas3d?

hi,
i managed to draw onto a canvas 3d overwriting postRender() of canvas3d.
  public void postRender()
    J3DGraphics2D g = getGraphics2D();
    //  TEST BEGINN
      Image pic = this.getToolkit().createImage("Graphics" + File.separator + "start2.png");
      MediaTracker helpMT = new MediaTracker(this);
      helpMT.addImage(pic,0);
      try{
        helpMT.waitForAll();
      } catch(InterruptedException e) {}
      g.drawImage(pic,10,10,200,200,this);
      g.setColor(Color.yellow);
      g.drawString("yellow",20,300);
      g.setPaintMode();
      g.setColor(Color.red);
      g.drawString("red",20,320);
      g.setColor(Color.green);
      g.drawString("green",20,340);
      g.setColor(Color.orange);
      g.drawString("orange",20,360);
      g.flush(true);
    //  TEST ENDE
  }However the colors are totally messed up. red is purple, for example, and images are also shown with the wrong colors. What am I doin wrong, and how can I fix it?
thanx,
Usul

Please, Im stuck.
Here are the only two classes needed:
Test2d.class:
import java.awt.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.swing.*;
public class Test2d extends JFrame
  public Test2d ()
    getContentPane().setLayout(new BorderLayout());
    Canvas3D c = new Visual_Canvas3D(SimpleUniverse.getPreferredConfiguration());
    getContentPane().add("Center", c);
    SimpleUniverse simpleU = new SimpleUniverse(c);
    BranchGroup scene = new BranchGroup();
    simpleU.getViewingPlatform().setNominalViewingTransform();
    scene.compile();
    simpleU.addBranchGraph(scene);
   public static void main(String[] args)
     Test2d mainApp = new Test2d();
     mainApp.setSize(800,600);
     mainApp.show();
}Visual_Canvas3D.class:
import java.awt.*;
import javax.media.j3d.*;
public class Visual_Canvas3D
extends Canvas3D
  public Visual_Canvas3D(GraphicsConfiguration gc)
    super(gc);
  public void postRender()
      J3DGraphics2D g = getGraphics2D();
      g.setColor(Color.red);
      g.drawString("red",20,320);
      g.setColor(Color.green);
      g.drawString("green",20,340);
      g.setColor(Color.orange);
      g.drawString("orange",20,360);
      g.setColor(Color.yellow);
      g.drawString("yellow",20,100);
      g.flush(false);
}Where could be the problem?

Similar Messages

  • How to add external images onto a control and still be able to resize

    Hello,
    I'm a LabVIEW newbie.  I'm trying to customize the appearance of my VIs, and one of the things I like to do is to import external image and paste it onto the faceplate of the gauge indicator.  I've followed the instruction in the Labview application note using the control editor and was able to paste the picture into indicator.  But when I use it in the front panel and resize the gauge indicator, the image (added as a decoration) doesn't resize together with the indicator.  My questions are:
    1. How to add external images onto a control/indicator and still be able to resize the image automatically when I resize the control/indicator?
    2. How to "add" a new part to an existing control/indicator?  It looks like I can only customize/modify the existing parts of the control/indicator in the control editor. 
    Any help is appreciated.  Thanks.

    1/ Do not use the image as an added decoration. Instead replace part of the control with the image. Tis is illustrated in the attached vi : the arrow was pasted as a decoration, and also used to replace the slide cursor. Changing the control size do not affect the decoration, but changes the cursor.
    2/ What do you mean by adding new parts to a control. We have just seen that it was possible to modify a control. Now, if you want to include additionnal functionnality, that's another story. You can replace parts of the control, and this can give interesting results.  You can edit a slide control, and replace the numeric indicator by another control, including a numeric indicator, that you can replace with etc...
    But there, it still the same info displayed under different forms. If you want to have several independant functions on the same control, such as a string display and a boolean and a numeric indicator, then that's a job for a cluster...
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Slide with Arrow.vi ‏13 KB

  • How to project an image onto a background image?

    Hi,
    I am looking for help with projecting an image over another image.
    I am looking for a similar effect to the image above where it looks like the image of the player as (physically) been projected onto the tunnel.
    Looking closely at the detail of the image you can see that the projection adjusts to the contours of the tunnel i.e. over the framing. This is what I specifically need some help with. I know how to overlay an image onto another using different layers but it doesn't really give a three-dimensional perspective and looks rather flat.
    Any help or advice would be greatly appreciated. Thanks
    Ravi.

    Hi Ravi -
    Could you post what you have done so far, and include your expanded layers panel? The source images would also be helpful, if possible!
    One thing you could try is creating a Displacement Map of your background tunnel image and then wrapping your overlay image to it. The video tutorial below shows you how to do this:
    Beside this, you might just have to spend time tweaking your image to create a realistic overlay. This includes adjusting lighting, but also distorting your overlay image. Have you tried using Edit > Transform > Perspective to align your image to the tunnel? The other Transform tools like Distort and Warp might also come in handy.
    I'm looking forward to helping you with this effect!
    Cheers,
    Kendall

  • How to draw an image at the center of a JscrollPane

    I have an image that I want to be centered in my JScrollPane. When I zoom-in, I want the image to fill the entire jscrollpane. When I zoom out it returns to the original scale. My problem is, when I open the image, it appears at the upper left corner of the JScrollPane. I want it centered. Also, when I zoom-in, it gets larger than the scrollpane. That is it goes beyond the boundaries of the JScrollpane. The function I am using to draw the image is:
    Image img = imp.getImage();
                   if (img!=null)
                        g.drawImage(img,0,0, (int)(srcRect.width*magnification), (int)(srcRect.height*magnification),
                        srcRect.x, srcRect.y, srcRect.x+srcRect.width, srcRect.y+srcRect.height, null);If I change the initial x,y values from (0,0) to any other value, it grays the upper left corner. So forinstance, if I did the following, the upper left corner of the scrollpane would become gray.
    g.drawImage(img,100,200, (int)(srcRect.width*magnification), (int)(srcRect.height*magnification),
                        srcRect.x, srcRect.y, srcRect.x+srcRect.width, srcRect.y+srcRect.height,null);How can I center my image in the scrollpane?

    When I zoom-in, I want the image to fill the entire jscrollpane. When I zoom out it returns to the original scaleSo why are you using a scroll pane? A scroll pane is used when its contents can potentially be larger than the scrollpane.
    Although it wasn't originally designed for this purpose you can probably use my [Background Panel|http://www.camick.com/java/blog.html?name=background-panel]. It supports displaying an image at its actual size as well as scaled to fit the panel. So you should just be able to toggle the style as required.

  • How to place an image onto each page

    Hi !
    How do I place an image onto each page (like a logo in a sidebar) using Pages 5.5 ?
    Thanks,
    Karsten

    Karsten,
    I am surprised no one has answered you yet - there are so many Pages users here.
    I am not a Pages user but I did find one way here on this thread in an answer from Arno Jannarelly
    insert image to header in Pages, template header
    "If you want any layout item to be repeated to all of the pages of your document, you just have to select the item(s), then go to Arrange/Section Masters/Move Object to Section Master.
    The good thing of this is that you can repeat any item or group of items placed anywhere you want on the page."
    Now when I first tried it I had no luck, until I selected the image and went to Arrange > Section Masters from the main menu, not on the right hand side from the Format/Document area.  
    From there there is an option: Move Object to Section Master.
    You then can format your image with drop shadows, opacity, etc. and it should be there on new pages in Pages. 

  • How to draw transparent image?

    i'm developing a java game, i wonder how to draw a transparent image, i'm using Image class, and Graphics class.

    http://search.java.sun.com/search/java/index.jsp?qp=forum%3A20&nh=10&qt=%2Btransparent+%2Bimage&col=javaforums

  • How to draw an image on transparent JPanel?

    I want to draw an image on the transparent JPanel. How to do it?
    I do like this:
    ( In constructor )
    setOpaque(false);
    String imageName = "coral.jpg";
    iimage_Bg = Toolkit.getDefaultToolkit().getImage(imageName);
    ( In paintComponent( Graphics g ) )
    Graphics2D g2D = (Graphics2D) g;
    g2D.drawImage( iimage_Bg, 0, 0, getWidth() , getHeight() , Color.white, null );
    But it doesn't work. Please help me!
    Thank you very much.
    coral9527

    Check the values that are returned from getWidth() and getHeight(). If they either are zero, then paintComponent(Graphics g) never gets called by the components paint(Graphics g) method. I cannot see the how this component has been added or displayed so can give no advice on how you can guarantee getting a valid size. If you have simply added it to a JFrame and called pack(), the size will be zero, as the panel does not contain any components (you would not have this problem if you were adding a JLabel with an ImageIcon for example). Try not packing the frame, and giving it a valid size.

  • How to draw an Image on a JPanel?

    Hi all,
    Can any one give code for drawing an image on a JPanel?
    thanks,
    amar

    That's for the JLabel right? ... For a JPanel on a JFrame, you could do something like this:
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    import java.net.URL;
    public class TestImagePaint  extends JFrame {
      private BjPanel bjp;
      public TestImagePaint( String imageName )   throws IllegalArgumentException {
        if ( imageName == null  ||  !( new File( imageName ).isFile() ) ) {
          throw new IllegalArgumentException( "\nIn TestImagePaint constuctor"
                                             +"\t IllegalArgumentException:" );
        bjp = new BjPanel( imageName );
        getContentPane().add( bjp );
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack();
        setBounds( 100, 100, 400, 300 );
        setVisible( true );
      public static void main( String[] argv ) {
        new TestImagePaint( argv[0] );
      public class BjPanel  extends JPanel {
        private URL   url;
        private Image image;
        public BjPanel( String imageName ) {
          try {
            url   = BjPanel.class.getResource( imageName );
            image = Toolkit.getDefaultToolkit().getImage( url );
            repaint();
          catch( Exception e ) {
            System.out.println( "Can't get Image: "+imageName+"\n\t"+e );
            System.exit( -1 );
        public void paint(Graphics g) {
          g.drawImage( image, 0, 0, this );
    }

  • How to draw an Image on a BufferedImage in a class that is not a Component?

    I have an Image object loaded from a file using Toolkit, I want to draw it on a BufferedImage using g.drawImage( x, y, width, height, ImageObserver );
    later on I want to save the BufferedImage in a jpeg file using the converter.
    Since my class is not a subclass of Component (Panel, Applet, Canvas... ) what do I pass along as ImageObserver, nothing seems to be working, I can draw anything using g.draw... except an Image.
    Thanks...
    Fco. Espaillat

    Try extending ImageObserver. You only have to implement one method, and its hardly an implementation. I ussually have that method return true regardless of what is going on and it works.
    But to discourage bad programming style does anyone there know what that method is suppossed to return and how to find that out?

  • How to embed an Image onto a Shape?

    I'd like to use Shape.contains() and intersects() functionalities on clipped free-form Images on a custom component. Could we embed an Image into a Shape? If the answe is yes, then, how?
    If Shape is not usable, then, how could we achieve similar functionalities on Images? Do we only have run-of-the-mill coord caluculation?

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class ImageShapes extends JPanel {
        BufferedImage image;
        Shape[] shapes;
        JLabel xLabel, yLabel;
        ImageShapes(BufferedImage image) {
            this.image = image;
        public void setCoordinates(Point p) {
            String sx = "";
            String sy = "";
            if(p != null) {
                sx = String.valueOf(p.x);
                sy = String.valueOf(p.y);
            xLabel.setText(sx);
            yLabel.setText(sy);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            if(shapes == null)
                initShapes();
            Shape origClip = g2.getClip();
            for(int j = 0; j < shapes.length; j++) {
                g2.setClip(shapes[j]);
                Rectangle r = shapes[j].getBounds();
                // center image in clip shape
                int x = r.x + (r.width - image.getWidth())/2;
                int y = r.y + (r.height - image.getHeight())/2;
                g2.drawImage(image, x, y, this);
                // smooth the edges of the clipped image
                g2.setClip(null);  // or origClip
                g2.setPaint(getBackground());
                g2.draw(shapes[j]);
        private void initShapes() {
            int w = getWidth();
            int h = getHeight();
            shapes = new Shape[3];
            shapes[0] = new Ellipse2D.Double(w/2, h/3, 175, 175);
            int R = 60;
            int sides = 5;
            int[][]xy = generateShapeArrays(w/4, h/4, R, sides);
            shapes[1] = new Polygon(xy[0], xy[1], sides);
            GeneralPath path = new GeneralPath();
            double x1 = w/4;
            double y1 = h*9/16;
            double ctrlx1 = w*9/32;
            double ctrly1 = h*5/16;
            double ctrlx2 = w*11/16;
            double ctrly2 = h*9/16;
            double x2 = w/4;
            double y2 = h*15/16;
            CubicCurve2D curve = new CubicCurve2D.Double(x1, y1, ctrlx1, ctrly1,
                                                         ctrlx2, ctrly2, x2, y2);
            path.append(curve, false);
            AffineTransform at = AffineTransform.getTranslateInstance(w/2, 0);
            at.scale(-1,1);
            Shape left = at.createTransformedShape(curve);
            path.append(left, false);
            shapes[2] = path;
        private int[][] generateShapeArrays(int cx, int cy, int R, int sides) {
            int radInc = 0;
            if(sides % 2 == 0)
                radInc = 1;
            int[] x = new int[sides];
            int[] y = new int[sides];
            for(int i = 0; i < sides; i++) {
                x[i] = cx + (int)(R * Math.sin(radInc*Math.PI/sides));
                y[i] = cy - (int)(R * Math.cos(radInc*Math.PI/sides));
                radInc += 2;
            // keep base of triangle level
            if(sides == 3)
                y[2] = y[1];
            return new int[][] { x, y };
        private JPanel getLabels() {
            xLabel = new JLabel(" ");
            yLabel = new JLabel(" ");
            Dimension d = new Dimension(45, 25);
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            gbc.weightx = 1.0;
            addComponents(new JLabel("x"), xLabel, panel, gbc, d, false);
            addComponents(new JLabel("y"), yLabel, panel, gbc, d, true);
            panel.setBorder(BorderFactory.createEtchedBorder());
            return panel;
        private void addComponents(JComponent c1, JComponent c2, Container c,
                                   GridBagConstraints gbc, Dimension d, boolean b) {
            gbc.anchor = gbc.EAST;
            c.add(c1, gbc);
            c2.setPreferredSize(d);
            gbc.weightx = b ? 1.0 : 0;
            gbc.anchor = gbc.WEST;
            c.add(c2, gbc);
        public static void main(String[] args) throws IOException {
            BufferedImage image = ImageIO.read(new File("images/cougar.jpg"));
            ImageShapes test = new ImageShapes(image);
            test.addMouseMotionListener(new ShapeFinder(test));
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(test);
            f.getContentPane().add(test.getLabels(), "Last");
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    class ShapeFinder extends MouseMotionAdapter {
        ImageShapes imageShapes;
        boolean hovering = false;
        ShapeFinder(ImageShapes c) {
            imageShapes = c;
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            boolean haveSelection = false;
            Shape[] shapes = imageShapes.shapes;
            if(shapes == null) return;
            for(int j = 0; j < shapes.length; j++) {
                if(shapes[j].contains(p)) {
                    haveSelection = true;
                    imageShapes.setCoordinates(p);
                    if(!hovering)
                        hovering = true;
            if(!haveSelection && hovering) {
                hovering = false;
                imageShapes.setCoordinates(null);
    }

  • How to superimpose still images onto video?

    Hi there,
    I'm an absolute beginner with iMovie (and video editing in general), so please forgive my ignorance!
    OK, my question is this: Is it possible to superimpose still images on top of video in iMovie, and if so how? I'm using iMovie because it has a reputation for ease of use, and yet I can't figure out how to do this... Basically, all I want to do is take a single piece of video about 5 minutes long and periodically fade in and fade out some still images on top of the action. Am I being too ambitious here?! Should I just give up on the idea...?!
    Any help or advice would be very gratefully received!
    Thanks.

    Just in case anyone else is interested in doing something similar - I found two (commercial) solutions to this problem:
    Gee Three software's 'Slick 4 - Hollywood edition' plug-ins package includes 'Picture-in-Picture' - $50 (also includes three other great effects): http://www.geethree.com/slick/V_04.html
    cf/x's 'Picture in Clip (Static)' does exactly the same, but only costs a bargain $1.50 - available here: http://www.imovieplugins.com/plugs/pictinclipstat.html
    Cheers!

  • How to drawing on image.

    Hi,
    I am developing one paint program. I am drawing over an image but the image is wash out when i am dragging mouse on canvas. But when i am clicking first on canvas before selecting any button. then selecting button after that it is working fine. Please help me
    Thanks in advance.
    Manveer

    The graphics context of your display object will erase when a repaint event is encountered--system generated or by code. If you do not have a persistent object displaying or the paint method does not containt the instruction to reproduce your image, then guess what? That's right you loose the image.
    You can paint to a BufferedImage and then do a drawImage in the overridden paint/paintComponent (AWT/SWING) of your display object. Without doing something like this, your image will dissapear mysteriously every time a system generated repaint happens.

  • How to insert an image onto a blank canvas doc?

    i am trying to create a blank canvas (700 width and 400 length) and then insert a photo onto it.  I am trying to make slides for a slideshow on my website's home page.
    PLEASE help.  i am new to photoshop and i have been searching for an answer.  I have a MAC

    This forum is intended to specifically support the Photoshop Getting Started experience, and in the future you'll likely get a faster response in the Photoshop forum. That said, here's what you want to do:
    Open Photoshop
    Select File, New
    Enter the size you want, you may need to change the size drop down to pixels
    Clock OK to create the blank canvas
    Select File, Place, this will let you select the image to insert
    I'll just add that if you want to create a web page slideshow, then you probably want to use Photoshop to edit or resize the images, and then Dreamweaver to actually build the web pager slideshow.
    --- Ben

  • How to import numerous images onto seprate consecutive frames?

    Hello. I was wondering if anyone knows if it is possible to
    import a whole bunch of images into flash but on consecutive
    frames. I have almost 3000 images that I need to be placed onto
    3000 frames.
    Thanks!

    If the images are named with consecutive numbers, then Flash
    will do exactly what you're asking. point to one file in the Import
    dialogue and Flash will identify the sequence and suggest you
    import them all.
    Good luck!

  • How to overlay an image onto separate layers while maintaining separate layers and adding no layers?

    I have a 6400x6400 image that I have divided into 100 640x640 layers. I want to overlay an separate image over the entire 6400x6400 document while making the individual layers hold part of the overlayed image.
    An anaology would be this:
    Imagine that I have created a giant board (6400x6400) and I have cut it into small pieces, where each piece is it's own layers. I want to put a picture to that entire puzzle, so that each layer holds a part of the picture and the picture is not it's own layer, but made up of the smaller layers.

    Here's one way to do it, I added the image in as a new layer, and used Clipping Masks to clip them to the layers.
    You can merge them into one layer by selecting both layers, right click and Merge Layers:
    Hope this helps!
    Julia

Maybe you are looking for

  • Error while trying to login dscc 6.2

    I am testing if I can install dscc 6.2 on WebSphere. When I tried to access the login page, I received the following error message: Show Details Hide Details Install Error Code: 3 Stack: com.sun.directory.common.slapx.AdmCmdErrorException: /iplanet/s

  • Java program to restart failed message in Adapter Engine

    Hi, I am using PI 7.0. Could anyone tell me whether there is an automated job or URL I can schedule in order to periodically resend messages sitting in the Adapter Engine receive queue that are in status System Error, Holding, or Waiting? I want to a

  • How to create an interactive mouse triggered table?

    I'm trying to create a VI for an experiment that will take measurements from 3 GPIB devices and put them in a table, with the front panel roughly looking like the one attached (panel.jpg).  I'm trying to have the panel work as follows: When the user

  • SQL Query join problem

    Hi, I have two tables in my db, the patient table holds details of patients, the contact table holds details of contacts related to the patient. patient table patientid - primary key - int patient name - varchar contact table contactid - primary key

  • Bridge does not see my external usb hard drive

    I have searched on this topic and the advice I've seen so far relates to when Bridge is set up to auto launch. That is not the case with me. I have Vista 32bit and CS3. I want to move files to it and make sure the keywords are ok. The drive is empty