bufferedimage

BufferedImage not being cleared before each rendering

旧巷老猫 提交于 2019-11-26 04:56:15
问题 I\'m trying to learn how to build a simple game through a tutorial i\'m watching. Up to now everything was fine, but when I move the image the previous image doesn\'t get erased or disposed. I\'m not sure exactly whats wrong, or why its happening. I have 3 classes, a main class, player class, and a bufferimageloader class. Main class: import java.awt.Canvas; import java.awt.Graphics; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage; import java.io.IOException; import

How to draw an image over another image?

半世苍凉 提交于 2019-11-26 04:27:49
问题 I have a Java project that\'s about traffic network simulation in a random city, I\'ve managed to figure out a way to implement this project, so I divided each intersection into a section which is basically an extended JPanel class (named Carrefour)...everything works well until I got stuck with how to draw vehicles and make them pass through roads. So my problem is how to draw an image (vehicle image) over an another image (road)? 回答1: If this is Swing, then draw the background image in a

Rotating BufferedImage instances

心不动则不痛 提交于 2019-11-26 04:26:57
问题 I am having trouble getting a rotated BufferedImage to display. I think the rotation is working just fine, but I can\'t actually draw it to the screen. My code: Class extends JPanel { BufferedImage img; int rotation = 0; public void paintComponent(Graphics g) { g.clearRect(0, 0, getWidth(), getHeight()); img2d = img.createGraphics(); img2d.rotate(Math.toRadians(rotation), img.getWidth() / 2, img.getHeight() / 2); g.drawImage(img, imgx, imgy, null); this.repaint(); } } This is not working for

Java converting Image to BufferedImage

独自空忆成欢 提交于 2019-11-26 03:09:54
问题 There is already question like this link on StackOverflow and the accepted answer is \"casting\": Image image = ImageIO.read(new File(file)); BufferedImage buffered = (BufferedImage) image; In my program I try: final float FACTOR = 4f; BufferedImage img = ImageIO.read(new File(\"graphic.png\")); int scaleX = (int) (img.getWidth() * FACTOR); int scaleY = (int) (img.getHeight() * FACTOR); Image image = img.getScaledInstance(scaleX, scaleY, Image.SCALE_SMOOTH); BufferedImage buffered =

How do you clone a BufferedImage

让人想犯罪 __ 提交于 2019-11-26 02:36:28
问题 I have an object which has many bufferedimages in it, I want to create a new object copying all the bufferedimages into the new object, but these new images may be altered and i don\'t want the original object images to be altered by altering the new objects images. is that clear? Is this possible to do and can anyone suggest a good way to do it please? I have thought of getSubImage but read somewhere that any changes to the subimage are relected back to the parent image. I just want to be

How to setSize of image using RescaleOp

北城以北 提交于 2019-11-26 02:26:28
问题 I am writing a test app. To set Alpha for image I use paintComponent method. Watch next snippet... public class TestImage extends JLabel{ public void paintComponent( Graphics g ) { super.paintComponent( g ); Graphics2D g2d=(Graphics2D)g; g2d.drawImage(this.bImage, rop, 0, 0); } public void setRescaleOp(RescaleOp rop){this.rop=rop;} } As you can see, g2d.drawImage(this.bImage, rop, 0, 0); does not allow to set width and height as if I use g.drawImage(bImage, 0, 0,width,height, null); So the

How to scale a BufferedImage

依然范特西╮ 提交于 2019-11-26 01:29:47
问题 Following the javadocs, I have tried to scale a BufferedImage without success here is my code: BufferedImage image = MatrixToImageWriter.getBufferedImage(encoded); Graphics2D grph = image.createGraphics(); grph.scale(2.0, 2.0); grph.dispose(); I can\'t understand why it is not working, any help? 回答1: AffineTransformOp offers the additional flexibility of choosing the interpolation type. BufferedImage before = getBufferedImage(encoded); int w = before.getWidth(); int h = before.getHeight();

Using Graphics2D to overlay text on a BufferedImage and return a BufferedImage

烈酒焚心 提交于 2019-11-25 23:25:24
问题 I have checked similarly named questions, but they don\'t answer this use case. Basically, I was to overlay some text (text) at a given coordinate (x,y) I have the below function in a package; protected BufferedImage Process2(BufferedImage image){ Graphics2D gO = image.createGraphics(); gO.setColor(Color.red); gO.setFont(new Font( \"SansSerif\", Font.BOLD, 12 )); gO.drawString(this.text, this.x, this.y); System.err.println(this.text+this.x+this.y); return image; } I feel like im missing

JComponents not showing up with picture background?

╄→гoц情女王★ 提交于 2019-11-25 22:58:35
问题 My components are not showing up. How do I fix this? Code: import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.*; public class login implements ActionListener{ JTextField gusername; JTextField gpassword; static String username; static String password; void logini() throws IOException { JFrame window = new JFrame(\"Login\