Good work for this library. I have developed a graphic library based on Java2D and now that we are switching on JavaFX, it is perfect.
I have one request for the drawImage methods. They all copy the provided image to an intermediate BufferedImage. Would it be possible to check if the provided image is actually a BufferedImage and perform the conversion only if it is not. For instance replace :
Code: Select all
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
BufferedImage img2 = new BufferedImage(width, height, 2);
Graphics2D g2 = img2.createGraphics();
g2.drawImage(img, 0, 0, width, height, (ImageObserver)null);
WritableImage fxImage = SwingFXUtils.toFXImage(img2, (WritableImage)null);
this.gc.drawImage(fxImage, (double)x, (double)y, (double)width, (double)height);
return true;
}
Code: Select all
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
BufferedImage img2 = convertToBufferedImage(img, width, height);
WritableImage fxImage = SwingFXUtils.toFXImage(img2, (WritableImage)null);
this.gc.drawImage(fxImage, (double)x, (double)y, (double)width, (double)height);
return true;
}
private BufferedImage convertToBufferedImage(Image img, int width, int height){
if(img instanceof BufferedImage){
return (BufferedImage)img;
}
BufferedImage img2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = img2.createGraphics();
g2.drawImage(img, 0, 0, width, height, (ImageObserver) null);
return img2;
}
Bastien