How to convert PlanarImage or BufferedImage (JAI) to Image (JavaFX)

417 Views Asked by At

I am trying to change the image represented in an ImageView instance, after manipulating it with JAI. JAI can output a PlanarImage, RenderedImage(non-awt), or BufferedImage(non-awt), but these are not valid types for ImageView construction.

import java.awt.image.renderable.ParameterBlock;
import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.ScrollPane;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.stage.Stage; 
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.media.jai.Interpolation;

public class A11 extends Application{

  int zoom = 100;
  ImageView img = new ImageView();
  Image src = new Image("file.bmp");

  public static void main(String args[]){
    launch(args); // start application
  }

  @Override 
  public void start(Stage window){
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(src); // source Image
    pb.add(zoom/100); // xScale
    pb.add(zoom/100); // yScale
    pb.add(0.0F); // xTranslate
    pb.add(0.0F); // yTranslate
    pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
    PlanarImage dest = JAI.create("scale", pb, null);

    // NEED TO CONVERT 'dest' TO 'destImage' HERE

    ImageView frame = new ImageView(destImage);
    ScrollPane pane = new ScrollPane(frame);
    window.setScene(new Scene(pane,800,600));
    window.show(); 
  }
}
0

There are 0 best solutions below