Created
July 4, 2012 12:52
-
-
Save rafaelportela/3047176 to your computer and use it in GitHub Desktop.
Code to get a generic BufferedImage from apple.awt.OSXImage (specific Apple Image implementation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* http://blog.pengoworks.com/index.cfm/2008/2/8/The-nightmares-of-getting-images-from-the-Mac-OS-X-clipboard-using-Java | |
*/ | |
public static BufferedImage getBufferedImage(Image img){ | |
if( img == null ) return null; | |
int w = img.getWidth(null); | |
int h = img.getHeight(null); | |
// draw original image to thumbnail image object and | |
// scale it to the new size on-the-fly | |
BufferedImage bufimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); | |
Graphics2D g2 = bufimg.createGraphics(); | |
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); | |
g2.drawImage(img, 0, 0, w, h, null); | |
g2.dispose(); | |
return bufimg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment