bufferedimage

Why does ToolkitImage getBufferedImage() return a null?

偶尔善良 提交于 2019-12-08 02:05:21
问题 I want to convert an Image to a BufferedImage . I know the following: Image tmp; ... //read, scale BufferedImage buffered = new BufferedImage(SMALL_SIZE, SMALL_SIZE, BufferedImage.TYPE_INT_RGB); buffered.getGraphics().drawImage(tmp, 0, 0, null); But it's really slow. I need BufferedImage , because I have to get pixel color data. I found a possible way to do it, without drawing: ToolkitImage ti = (ToolkitImage) tmp; BufferedImage buffered = tmp.getBufferedImage(); But it always returns null .

Java - Red, Green, Blue to getRGB

筅森魡賤 提交于 2019-12-07 12:16:25
问题 By calling getRGB(int x, int y) with a BufferedImage object, one gets a single, negative number. How can I convert three different values (a red, a green, and a blue) into this single, negative number? 回答1: Using the Color class: new Color(r, g, b).getRGB() 回答2: BufferedImage ends up delegating to java.awt.image.ColorModel which uses the following code: public int getRGB(Object inData) { return (getAlpha(inData) << 24) | (getRed(inData) << 16) | (getGreen(inData) << 8) | (getBlue(inData) << 0

Do certain image file types always correspond with certain BufferedImage constant types?

耗尽温柔 提交于 2019-12-07 07:36:05
问题 The BufferedImage class in Java contains a getType() method which returns an integer correlating with a BufferedImage constant type variable describing some information about how the image is encoded (you can look at the BufferedImage source to determine what number corresponds to what constant type variable). For instance, if it returns the integer corresponding with BufferedImage.TYPE_3BYTE_BGR , then that means that the BufferedImage is an 8-bit RGB image with no alpha and with blue, green

Safe to update separate regions of a BufferedImage in separate threads?

北慕城南 提交于 2019-12-07 04:50:03
问题 I have a collection of BufferedImage instances, one main image and some subimages created by calling getSubImage on the main image. The subimages do not overlap. I am also making modifications to the subimage and I want to split this into multiple threads, one per subimage. From my understanding of how BufferedImage , Raster and DataBuffer work, this should be safe because: Each instance of BufferedImage (and its respective WritableRaster and SampleModel ) is accessed from only one thread.

What is the difference between the ways to read an Image file in Java?

别来无恙 提交于 2019-12-07 03:48:12
问题 There are various ways of reading an image file in java such as BufferedImage and ImageIcon to name a few. I want to know what is the difference between these cases? Are they context dependent that in a particular case only one of them can be used? What would be the best way of reading a image selected by JFileChooser by the user and separating the color channels of an image? 回答1: A good way is to use the different ImageIO.read methods, which return BufferedImage objects. Image is an abstract

BufferedImage color saturation

微笑、不失礼 提交于 2019-12-07 03:35:53
问题 I'm writing a simple scanning application using jfreesane and Apache PDFBox. Here is the scanning code: InetAddress address = InetAddress.getByName("192.168.0.17"); SaneSession session = SaneSession.withRemoteSane(address); List<SaneDevice> devices = session.listDevices(); SaneDevice device = devices.get(0); device.open(); device.getOption("resolution").setIntegerValue(300); BufferedImage bimg = device.acquireImage(); File file = new File("test_scan.png"); ImageIO.write(bimg, "png", file);

Fastest way to compare pixel values between two BufferedImages?

梦想与她 提交于 2019-12-07 03:22:33
问题 I have a BufferedImage of type TYPE_INT_BGR. I need to do a pixel-by-pixel comparison to another BufferedImage to compute the "distance" between the two images. I have something that works, but is slow. I get a pixel from the "reference" image, break it up into RGB bytes with: int pixel = referenceImage.getRGB(col, row); int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel) & 0xff; I compare the r/g/b values to the corresponding pixel of the candidate image, and

Java BufferedImage saves with unwanted background color

放肆的年华 提交于 2019-12-07 03:13:15
问题 Thanks ahead of time for the help Description: The program draws, displays, and saves an image. It works as following: the object itself extends Frame. In the constructor, the object creates a BufferedImage, and calls a method that draw onto that image. Then, it displays the image onto the Frame. Finally, it saves the image into a file (I don't care what format it uses). The main program creates the object, which does the rest. Problem: The saved file always has a colored background! This is

How to convert java swing panel to quality image

半城伤御伤魂 提交于 2019-12-06 20:54:33
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(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); gg.setRenderingHint(RenderingHints

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

半世苍凉 提交于 2019-12-06 14:52:36
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 slowly (takes a considerable amount of time to resize the image and the like): Exception in thread