bufferedimage

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

蹲街弑〆低调 提交于 2019-12-05 10:55:55
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. The shared ColorModel is immutable The DataBuffer has no fields that can be modified (the only thing that

JavaFX: Fastest way to write pixels to PixelWriter

旧巷老猫 提交于 2019-12-05 10:46:40
I'm looking for the fastest way to write pixels on javafx.scene.image.Image . Writing to BufferedImage 's backing array is much faster. At least on the test image I made it took only ~20ms for BufferedImage , WritableImage on the other hand took ~100ms. I already tried SwingFXUtils but no luck. Code for BufferedImage (faster): BufferedImage bi = createCompatibleImage( width, height ); WritableRaster raster = bi.getRaster(); DataBufferInt dataBuffer = (DataBufferInt) raster.getDataBuffer(); System.arraycopy( pixels, 0, dataBuffer.getData(), 0, pixels.length ); Code for WritableImage (slower):

How to get a BufferedImage from a Component in java?

帅比萌擦擦* 提交于 2019-12-05 06:58:46
I know how to get a BufferedImage from JComponent, but how to get a BufferedImage from a Component in java ? The emphasis here is an object of the "Component" type rather than JComponent. I tried the following method, but it return an all black image, what's wrong with it ? public static BufferedImage Get_Component_Image(Component myComponent,Rectangle region) throws IOException { BufferedImage img = new BufferedImage(myComponent.getWidth(), myComponent.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); myComponent.paint(g); g.dispose(); return img; } Component has a

BufferedImage color saturation

痴心易碎 提交于 2019-12-05 06:52:44
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); device.close(); And making PDF: PDDocument document = new PDDocument(); float width = bimg.getWidth();

Java BufferedImage saves with unwanted background color

时光怂恿深爱的人放手 提交于 2019-12-05 06:43:17
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 especially wierd since the displayed image is fine. If I use "jpg" format with ImageIO.write(), the

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

时光毁灭记忆、已成空白 提交于 2019-12-05 05:56:25
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? Alexis Dufrenoy A good way is to use the different ImageIO.read methods, which return BufferedImage objects. Image is an abstract class, so I think the real question is which subclass is more efficient for your program.

java Buffered Image : Detecting black pixels

跟風遠走 提交于 2019-12-05 05:23:28
I have this simple code to go through a 24bit color windows bmp file BufferedImage mapa = BMPDecoder.read(new File("maps/map.bmp")); final int xmin = mapa.getMinX(); final int ymin = mapa.getMinY(); final int ymax = ymin + mapa.getHeight(); final int xmax = xmin + mapa.getWidth(); for (int i = xmin;i<xmax;i++) { for (int j = ymin;j<ymax;j++) { int pixel = mapa.getRGB(i, j); if (pixel == 0) { System.out.println("black at "+i+","+j); } } } However, when testing on a completely black image, I get this value at pixel : -16777216 . I was hoping to get a 0x0. How can I test for black pixels (or any

Java BufferedImage how to know if a pixel is transparent

给你一囗甜甜゛ 提交于 2019-12-05 03:24:40
I'm going to use the getRGB method of BufferedImage. I want to check the pixels of an image and see which of them have transparency (in general the pixels I will have that are transparent will be totaly transparent). How can I get it from the int that getRGB returns? chubbsondubs BufferedImage img = .... public boolean isTransparent( int x, int y ) { int pixel = img.getRGB(x,y); if( (pixel>>24) == 0x00 ) { return true; } return false; } Of course img has to be in the correct format TYPE_4BYTE_ABGR or some format that supports alpha channels else if will always be opaque (ie 0xff). the correct

How to convert a BufferedImage to 8 bit?

会有一股神秘感。 提交于 2019-12-05 02:43:20
I was looking at the ImageConverter class, trying to figure out how to convert a BufferedImage to 8-bit color, but I have no idea how I would do this. I was also searching around the internet and I could find no simple answer, they were all talking about 8 bit grayscale images. I simply want to convert the colors of an image to 8 bit... nothing else, no resizing no nothing. Does anyone mind telling me how to do this. This code snippet from the article "Transparent gifs in Java" at G-Man's Uber Software Engineering Blog works well: public static void main(String[] args) throws Exception {

Drawing an image in JScrollPane within scale

时间秒杀一切 提交于 2019-12-04 18:12:08
I have a scrollpane where load an image. I wont this image with her natural size, and if this image is too big, I wont activated the scrollbar, but this instruction g.drawImage(immagine, 0, 0, getWidth(), getHeight(), this); scaled image for placing in scrollpane. What can I do? Class Gui: import java.awt.*; import java.awt.event.*; import java.io.File; import javax.swing.*; public class Gui implements ActionListener { private JFrame frmEditor; private Mappa content; private JMenuItem mntmSfondo; private JScrollPane scrollabile; /** * Launch the application. */ public static void main(String[]