bufferedimage

BufferedImage producing black background

核能气质少年 提交于 2019-12-08 16:45:55
问题 Alright so I'm making a game, and I'm trying to modify the original hit marker image by adding text on it, and I'm using the following code: import javax.swing.ImageIcon; import javax.swing.Timer; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; public class HitMarker { public static final Image rangeHitMarker = new ImageIcon(HitMarker

BufferedImage.createGraphics() memory leak

北慕城南 提交于 2019-12-08 13:43:03
问题 The code below produces a memory leak. public static BufferedImage mergeImages2(BufferedImage base, Collection<Light> images) { BufferedImage output = new BufferedImage(base.getWidth(), base.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = output.createGraphics(); g.drawImage(base, 0, 0, null); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, 1.0f)); for (Light l : images) { g.drawImage(l.LIGHT_IMAGE, l.x, l.y, null); l.LIGHT_IMAGE.flush(); } g.dispose(); output.flush

How to clear pixel of BufferedImage in java?

六眼飞鱼酱① 提交于 2019-12-08 12:00:52
问题 In java, I read an image and then go through the pixels and if its color distance is < 30, then I want to clear the image by changing its alpha to 0. This is my code: But this is not working. It is having no effect... Does anyone see the problem? Thanks import java.awt.Color; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import javax.imageio

Java Creating Instance of BufferedImage Freezes Program

偶尔善良 提交于 2019-12-08 08:30:33
I'm experiencing something really strange, and I don't know what's causing it at all. This is the problematic line of code: BufferedImage out = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB); Upon calling this, all threads freeze and everything stops. I've tried putting this in its own thread and the main thread, the same thing occurs. I am using LWJGL3, so that might be an issue, but I don't see how it could be. Edit: Does not occur in a blank project without LWJGL in or out of -XstartOnFirstThread Ok! I found the solution. Turns out, all it takes is the following JVM argument:

How to convert java swing panel to quality image

∥☆過路亽.° 提交于 2019-12-08 07:25:30
问题 my panel looks like: when I convert to image public BufferedImage createImage(JPanel panel) { int w = (int) PageSize.A4.getWidth();//panel.getWidth(); int h = (int) PageSize.A4.getHeight();//panel.getHeight(); BufferedImage originalImage = new BufferedImage(panel.getHeight(), panel.getWidth(), BufferedImage.TYPE_BYTE_INDEXED); Graphics2D gg = originalImage.createGraphics(); gg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); gg.setRenderingHint

Resizing image to fit frame

谁说我不能喝 提交于 2019-12-08 05:07:57
问题 A part of my application is working as a tutorial. For that purpose I got JPanels that display a JLabel that has an image as content. Although when the image is larger than what fits the screen it will just cut what doesn't fit. What I need to do is resize the image so that I will fit the space the JLabel is given. Also tried using JScrollPanes but didn't make any difference(although I prefer to resize image). I tried getting a scaled instance of the image using Image scaledImg = myPicture

Creating very large image files with BufferedImage, strange issues depending on compilation and computer

江枫思渺然 提交于 2019-12-08 04:11:25
问题 I'm attempting to create a very large image in Java like so: BufferedImage bi = new BufferedImage(58240, 1664, BufferedImage.TYPE_INT_RGB); obviously the image is very large. Now the issue I'm having is that it seems to work fine 100% on some computers but really slowly on others (and no this has NOTHING to do with specs). My most major breakthrough came in Eclipse, the IDE refused to actually display the image and instead threw an error on one of the computers which displays the image really

Drawing a transparent BufferedImage over a non-transparent BufferedImage

时光怂恿深爱的人放手 提交于 2019-12-08 04:11:08
问题 I'm having a problem when it comes to drawing BufferedImages. I'm working on a 2D tile-based map editor and when I draw a tile, it first draws the lower layer followed by the top layer. like so: public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(tileLayer, 0, 0, null); g.drawImage(objectLayer, 0, 0, null); } Note that this method is in a class which extends JLabel. It's actually redrawing the ImageIcon which was set. Now, to understand the problem you must realize

How to rotate a buffered image without cropping it? Is there any way to rotate a JLayeredPane or JLabel?

风格不统一 提交于 2019-12-08 03:36:56
问题 I had searched about it but I did not get straight forward answer. I want a buffered image to be rotated but not cropped I knew the new dimensions are gonna be some thing like this int w = originalImage.getWidth(); int h = originalImage.getHeight(); double toRad = Math.toRadians(degree); int hPrime = (int) (w * Math.abs(Math.sin(toRad)) + h * Math.abs(Math.cos(toRad))); int wPrime = (int) (h * Math.abs(Math.sin(toRad)) + w * Math.abs(Math.cos(toRad))); Provide me a method for that. BTW is

Java Creating Instance of BufferedImage Freezes Program

随声附和 提交于 2019-12-08 03:22:12
问题 I'm experiencing something really strange, and I don't know what's causing it at all. This is the problematic line of code: BufferedImage out = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB); Upon calling this, all threads freeze and everything stops. I've tried putting this in its own thread and the main thread, the same thing occurs. I am using LWJGL3, so that might be an issue, but I don't see how it could be. Edit: Does not occur in a blank project without LWJGL in or out of