Results 1 to 5 of 5
  1. #1
    ajeeb is offline Member
    Join Date
    Dec 2008
    Posts
    30
    Rep Power
    0

    Default JavaFX not able to read images

    Hi,
    My javafx code is not able to read image and hence not able to display it on runtime. Am using Net Beans IDE. Other nodes (Circle & Text are appearing fine). Any ideas please ?
    Code:
    Java Code:
    package test2;
    
    import javafx.scene.Group;
    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;
    import javafx.scene.paint.Color;
    import javafx.scene.Scene;
    import javafx.scene.shape.Circle;
    import javafx.scene.text.Text;
    import javafx.stage.Stage;
    
    Stage {
        title: "Group-Nodes-Transformation"
        scene: Scene {
            width: 600
            height: 600
            content: Group {
                content: [
                    Circle {
                        centerX: 300
                        centerY: 300
                        radius: 250
                        fill: Color.WHITE
                        stroke: Color.BLACK
                    },
                    Text {
                        x: 300
                        y: 300
                        content: "Mr. Duke"
                    },
                    ImageView {
                        image: Image {
                            url: "D:\\TEST\\Documents\\duke.png"
                            width:50
                            height:50
                        }
                    }
                ]//content
            }//Group
        }//Scene
    }//Stage

  2. #2
    sithumm is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default Alternate way read images in JavaFx

    Hey ajeeb,

    I got the same problem. I'll give you a solution as soon as i get one.
    Last edited by sithumm; 04-07-2009 at 10:18 AM.

  3. #3
    sithumm is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default JavaFX provides an alternate way!!!!!!!

    Hey ajeeb,

    I don't know whether you got the answer for this question elsewhere. I joined this forum just yesterday. Although your post is quite old I thought of answering bcoz no one else has answered.
    Answer is quite simple. "url" instance varable does not support system paths. So JavaFX provides "fromBuffereImage(java.awt.image.BufferedImage ): Image" method which has a BufferedImage argument and returns a JavaFX Image object.
    You have to modify your code as follows:

    package test2;

    import javafx.scene.Group;
    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;
    import javafx.scene.paint.Color;
    import javafx.scene.Scene;
    import javafx.scene.shape.Circle;
    import javafx.scene.text.Text;
    import javafx.stage.Stage;
    //Add imports for ImageIO, File, BufferedImage

    var img = Image {};

    Stage {
    title: "Group-Nodes-Transformation"
    scene: Scene {
    width: 600
    height: 600
    content: Group {
    content: [
    Circle {
    centerX: 300
    centerY: 300
    radius: 250
    fill: Color.WHITE
    stroke: Color.BLACK
    },
    Text {
    x: 300
    y: 300
    content: "Mr. Duke"
    },
    ImageView {
    image: img.fromBufferedImage(ImageIO.read(new File("D:\\TEST\\Documents\\duke.png")));
    }
    ]//content
    }//Group
    }//Scene
    }//Stage
    Last edited by sithumm; 04-08-2009 at 05:15 PM.

  4. #4
    netsuvi is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default

    just make a url out of the url like
    url: "file:\D:\\TEST\\Documents\\duke.png"

    and it will work. At least on windows. On Linux I am still working to get this running.

    Cheers
    suvi.org

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Welcome! Please don't hijack other people's threads and find the appropriate subforum for your posts. Introductions - Java Forums
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. JavaFX Script and JavaFX Mobile
    By levent in forum Java Software
    Replies: 1
    Last Post: 01-27-2010, 04:48 PM
  2. Replies: 5
    Last Post: 10-17-2008, 02:13 PM
  3. Indentation Size Reset While Coding JavaFX
    By JDCAce in forum NetBeans
    Replies: 0
    Last Post: 10-06-2008, 09:28 PM
  4. images
    By amith in forum AWT / Swing
    Replies: 3
    Last Post: 06-27-2008, 08:38 PM
  5. Lobo Browser 0.98 - Now With JavaFX Support
    By lobochief in forum Java Software
    Replies: 0
    Last Post: 03-10-2008, 03:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •