Copy and paste of images from web browser (Firefox, Chrome and Safari) stopped working on my OSX machine, it is ok on PC.
I tracked it down to the fact that I expected data with the flavor of image/x-java-image;class=java.awt.Image to always be a buffered image later in my code
I need it to be a BufferedImage so I can find the size of the image and access the data.
However now instead of it returning a BufferedImage it returns a sun.awt.image.MultiResolutionCachedImage, and to get the Buffered data I need to call getResolutionVariants which is only defined in the interface it implements sun.awt.image.MultiResolutionImage
So now my code has to refer directly to sun classes, surely this is wrong ?
Image image = null;
ImageCell imageCell = null;
try
{
image = (Image) trans.getTransferData(FileDropTarget.imageFlavor);
}
catch(Exception e)
{
MainWindow.logger.log(Level.WARNING,"Unable to extract image from drop data:"+e.getMessage(),e);
}
if(image!=null && image instanceof sun.awt.image.MultiResolutionImage)
{
for(Image i:mri.getResolutionVariants())
{
if(i instanceof BufferedImage)
{
ImageData imageData = new ImageData((BufferedImage) i, "downloaded:" + new Random().nextInt());
imageCell = new ImageCell(imageData);
return imageCell;
}
}
}
The other thing I notice if I put some debugging is it always uses MultiResolutionCachedImage even when there is in fact only a single image !
It does seem these classes have been added to the java package in Java 9 but Im using Java 8.