Posts

Showing posts with the label swing

Black flashing around drawn image

Black flashing around drawn image I'm currently trying to draw an image to a JFrame (just a nonsense test image). In the code bite below, the image is drawn to the JFrame, but the area around the image that doesn't fill JFrame is black that rapidly flashes. Here is the code below: try { myImage = ImageIO.read(ImagesMain.class.getResource("/Textures/TestImage.png")); }catch(Exception e) { e.printStackTrace(); } BufferStrategy strategy = null; while(strategy == null) {//I know this is terrible practice, just doing this way because its inside main strategy = myCanvas.getBufferStrategy(); if(myCanvas.getBufferStrategy() == null) { myCanvas.createBufferStrategy(3); } } myFrame.setVisible(true); //Rendering part while(true) { do { do { g = strategy.getDrawGraphics(); g.setColor(Color.WHITE); g.drawImage(myImage, 20, 20, null...