Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class Main {
    /**
     * Creates an image canvas with the given width and height.
     */
    public static Canvas createImageCanvas(String url, double width, double height) {
        ImageView img = new ImageView(new Image(url, width, height, false, true));
        final Canvas canvas = new Canvas(width, height);
        final GraphicsContext gc = canvas.getGraphicsContext2D();
        gc.drawImage(img.getImage(), 0, 0);

        return canvas;
    }
}