bufferedimage

Can't draw a Buffered Image

霸气de小男生 提交于 2019-12-11 11:46:24
问题 I'm using this code to try and draw an image : g.drawImage(Tile.background, (int)spritePositionX, (int)spritePositionY, null); Here is the my tile class for Tile.background : public class Tile { public static int size = 40; public static BufferedImage terrain, background, items, characters; public Tile(){ try{ Tile.background = ImageIO.read(new File("res/bg.png")); Tile.terrain = ImageIO.read(new File("res/terrain.png")); Tile.items = ImageIO.read(new File("res/items.png")); Tile.characters =

Scalable images in Java

北城以北 提交于 2019-12-11 11:27:52
问题 I anticipate using some images in my Java application. These images will be drawn onto my JPanel using g.drawImage() . The JPanel is resizable and the images should scale as the JPanel increases/decreases in size Two questions: What image format is best for this type of desired scalable image? For instance, in this application, an image of size 100x100 may be scaled into an image of size 30x30 or 10x10 or 300x300. How can I write code to do this scaling? 回答1: Take a look at Java: maintaining

Java Applet to BufferedImage [duplicate]

*爱你&永不变心* 提交于 2019-12-11 11:24:13
问题 This question already has an answer here : Swing: Obtain Image of JFrame (1 answer) Closed 6 years ago . I created a JFrame that loads an external applet for a game like so: //Setup everything for the Stub.. Below adds the stub to the applet and creates it. DownloadFile(new URL(World + "/" + Archive), "./gamepack.jar"); CAppletStub Stub = new CAppletStub(new URL(World), new URL(World), this.Parameters); applet = (Applet) new URLClassLoader(new URL[] {new URL(World.toString() + "/" + Archive)}

Java Graphics2D Drawing into BufferedImage

强颜欢笑 提交于 2019-12-11 11:15:58
问题 I'm busy fiddling around with Java's Graphics2D and drawings and I although it works I am not sure how to create a BufferedImage from this graphic which it seems I need to do in order so save it somewhere. I have something very basic because I'm trying to understand how this works import javax.swing.*; import javax.imageio.*; import java.awt.*; import java.awt.image.*; import java.io.*; public class myFrame { public static void main(String[] args) { JFrame lv_frame = new JFrame(); lv_frame

coordinates out of bound:bufferedimage

邮差的信 提交于 2019-12-11 09:54:08
问题 I made a program to separate red blue and green components of a image but the code below gives an error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds! at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:318) at java.awt.image.BufferedImage.getRGB(BufferedImage.java:888) at rgb.Rgb.main(Rgb.java:46): Here is the source code: public static void main(String[] args) { String type = "jpg"; BufferedImage img = null; try

repaint() not calling PaintComponent to use Graphics2D

流过昼夜 提交于 2019-12-11 06:44:28
问题 I have spent a few days now trying to get the Graphics2D class to work within my code. I have it structured in such a way that when a click event is registered the call to repaint is done, however this only produces a nullpointer exception when it reaches the stage of calling repaint(). It is all working as expected when debugging and not called from within the paintComponent method, however when trying to call the code properly using paintComponent and repaint() to allow the Graphics2D class

Paint BufferedImage on JFrame and write to File

陌路散爱 提交于 2019-12-11 06:25:36
问题 I'm trying to code a program, that reads an Image into a BufferedImage, paint it on the JFrame, paint circles in it, and writes it to a File. The following code will do all of it except the content of the saved file. The saved image only contains the untouched BufferedImage. No Circles ;) I already treid to figure it out by changing and adding some code, but it didn't help a lot. public class PaintImage extends Component { BufferedImage img; private int pngWidth, pngHeight; public int

Double buffered image example in Jpanel

為{幸葍}努か 提交于 2019-12-11 04:58:41
问题 I would know if my implementation is correct for double buffered image.. because i note that tremble the borders of my image that i move in the screen ... It is normal?? public void paintComponent(Graphics g) { Image bufferimage= createImage(180,180); Graphics dbg= bufferimage.getGraphics(); //clean the screen dbg.setColor(new Color(100,100,100)); dbg.fillRect(0,0,getWidth(),getHeight()); if (game_is_running) { // draw various type of object with drawImage for(int i=0; list[i]!=null; i++) {

Converting Image to BufferedImage

荒凉一梦 提交于 2019-12-11 02:56:01
问题 I'm having an image on disk. I want to convert it to a BufferedImage so that i can apply filters on it. Is there any way to do this? 回答1: use ImageIO.read(File) . It returns BufferedImage : BufferedImage image = ImageIO.read(new File(filename)); 回答2: Try this, Use class "javax.imageio.ImageIO" like BufferedImage originalImage = ImageIO.read(new File("c:\\image\\mypic.jpg")); Also refer this link http://www.dzone.com/snippets/converting-images 回答3: The safest way to convert a regular Image to

Help with eraser from buffered Image

感情迁移 提交于 2019-12-11 02:24:47
问题 So below I am working on a paint type project for class that lets you draw shapes lines etc, now my professor wants us to add a eraser tool that lets you erase parts of the image, it is on a buffered image any ideas? im fresh out import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.*; public class PaintProgram extends JPanel implements MouseListener