BufferedImage turns all black after scaling via canvas <p>I have a method which purpose is to receive an image and return it scaled down. The reason I'm using canvas is that I believe that it will scale the image automatically for me.</p> <p>After the conversion the outputimage is completely black. Anyone have any clue on how to fix this?</p> <pre><code>try { InputStream in = new ByteArrayInputStream(f.getBytes()); BufferedImage image = ImageIO.read(in); File beforescale = new File("beforescale.jpg"); ImageIO.write(image, "jpg", beforescale); //works Canvas canvas = new Canvas(); canvas.setSize(100, 100); canvas.paint(image.getGraphics()); image = canvasToImage(canvas); File outputfile = new File("testing.jpg"); ImageIO.write(image, "jpg", outputfile); //all black response.getWriter().print(canvas); } catch (Exception ex) { ex.printStackTrace(); } } private BufferedImage canvasToImage(Canvas cnvs) { int w = cnvs.getWidth(); int h = cnvs.getHeight(); int type = BufferedImage.TYPE_INT_RGB; BufferedImage image = new BufferedImage(w,h,type); Graphics2D g2 = image.createGraphics(); cnvs.paint(g2); g2.dispose(); return image; } </code></pre>