bufferedimage

Image vs. BufferedImage

删除回忆录丶 提交于 2019-12-03 23:17:24
Whenever dealing with the loading and rendering of images in Java, I have previously always used BufferedImage s to store and manipulate the images in memory. However, I have recently come across a few different sites that use the Image class instead of BufferedImage and this got me wondering - what are the differences? I'm aware that a BufferedImage has a larger/optimised toolset, but does come at any cost? If so, when does this cost become noticeable? In which situations would you use an Image over a BufferedImage , or vice-versa? BufferedImage extends Image . Image is just a base abstract

Creating a BufferedImage causes GLFW in the LWJGL to lock up (Java)

旧时模样 提交于 2019-12-03 22:59:22
问题 There is a link to download the project below. The project already contains the LWJGL. Just open it with eclipse and tell me I'm not going crazy I'm experimenting with the LWJGL for the first time and have managed to get the sample code on the LWJGL website to work. The odd thing is, if I create an instance of a BufferedImage anywhere in the program, it causes the whole thing to lock up. I've managed to narrow it down to the ColorModel class (which is used by BufferedImage) but can't figure

Converting BufferedImage to Mat (OpenCV) in Java [duplicate]

夙愿已清 提交于 2019-12-03 22:06:29
问题 This question already has answers here : Converting BufferedImage to Mat in opencv (7 answers) Closed 3 years ago . I've tried this link and have the code below. My program imports images in a BufferedImage format and then displays it to the users. I'm using the matchingTemplate function in OpenCV which requires me to convert it to a Mat format. The code works if I import the image -> convert it to Mat then save the image using imwrite. The program also allows the user to crop an image and

Resizing an image in swing

ε祈祈猫儿з 提交于 2019-12-03 20:59:59
问题 I have snippet of code that I am using for the purpose of resizing an image to a curtain size (I want to change the resolution to something like 200 dpi). Basically the reason I need it is because I want to display the image that the user have picked (somewhat large) and then if the user approves I want to display the same image in a different place but using a smaller resolution. Unfortunately, if I give it a large image nothing appears on the screen. Also, if I change imageLabel.setIcon

Get average color on bufferedimage and bufferedimage portion as fast as possible

那年仲夏 提交于 2019-12-03 20:13:57
I am trying to find image in an image. I do this for desktop automation. At this moment, I'm trying to be fast, not precise. As such, I have decided to match similar image solely based on the same average color. If I pick several icons on my desktop, for example: And I will search for the last one (I'm still wondering what this file is): You can clearly see what is most likely to be the match: In different situations, this may not work. However when image size is given, it should be pretty reliable and lightning fast. I can get a screenshot as BufferedImage object: MSWindow window = MSWindow

Difference between the Image and BufferedImage in Java

房东的猫 提交于 2019-12-03 19:21:01
问题 What is the difference between Image and BufferedImage? Can I create a BufferedImage directly from an Image source "image.png"? 回答1: If you are familiar with Java's util.List, the difference between Image and BufferedImage is the same as the difference between List and LinkedList. Image is a generic concept and BufferedImage is the concrete implementation of the generic concept; kind of like BMW is a make of a Car. 回答2: Image is an abstract class. You can't instantiate Image directly.

Save buffered image with transparent background

主宰稳场 提交于 2019-12-03 17:06:59
问题 I'm saving the image of a signature as a .jpg picture. I use graphic2d to paint on the image every pixel of the signature (gotten with a signature tablet) and it works perfectly but I'm always gettin a white background. If I want to put the signature on a PDF document, the borders of the white square of the jpg image covers some of the words of the PDF. What I want to get is to save the jpg image with a transparent background, so when I put it on the PDF there are no words covered with the

Working in a BufferedImage's int[] pixels array

穿精又带淫゛_ 提交于 2019-12-03 15:25:20
When working with BufferedImage using the setRGB and getRGB methods, I noticed two things: the setRGB and getRGB methods can be incredibly slow on some systems (as much as two orders of magnitude slower than modifiyng the int[] array). there are no guarantee that a getRGB following a setRGB will give back the same pixel you passed This last point is basically pretty clear from the JavaDoc of setRGB , which states: ...For images with an IndexColorModel, the index with the nearest color is chosen. Seen I can work directly in a BufferedImage's int[] pixels, which I can access to by doing, for

How to create a BufferedImage from raw data

折月煮酒 提交于 2019-12-03 13:15:38
I'm trying to get a BufferedImage from raw samples, but I get exceptions about trying to read past the available data range which I just don't understand. What I'm trying to do is: val datasize = image.width * image.height val imgbytes = image.data.getIntArray(0, datasize) val datamodel = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, image.width, image.height, Array(image.red_mask.intValue, image.green_mask.intValue, image.blue_mask.intValue)) val buffer = datamodel.createDataBuffer val raster = Raster.createRaster(datamodel, buffer, new Point(0,0)) datamodel.setPixels(0, 0, image

How to get scaled instance of a bufferedImage

落花浮王杯 提交于 2019-12-03 07:20:23
I wanted to get scaled instance of a buffered image and I did: public void analyzePosition(BufferedImage img, int x, int y){ img = (BufferedImage) img.getScaledInstance(getWidth(), getHeight(), Image.SCALE_SMOOTH); .... } but I do get an exception: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: sun.awt.image.ToolkitImage cannot be cast to java.awt.image.BufferedImage at ImagePanel.analyzePosition(ImagePanel.java:43) I wanted then to cast to ToolkitImage then use the method getBufferedImage I read about in other articles. The problem is there is no class such as sun.awt