bufferedimage

java print screen two monitors

巧了我就是萌 提交于 2019-12-21 04:23:09
问题 I'm trying to use print screen image area to get 2 monitors, but only works for one monitor. Can you advise me how to get figure 2 monitors? Robot robot = new Robot(); Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage capture = new Robot().createScreenCapture(screenRect); ImageIO.write(capture, "bmp", new File("printscreen.bmp")); 回答1: Union together the bounds of each screen: Rectangle screenRect = new Rectangle(0, 0, 0, 0); for (GraphicsDevice

Coloring an area of BufferedImage

六眼飞鱼酱① 提交于 2019-12-20 06:28:46
问题 I want to color a sub area of a BufferedImage I have. I am presently doing: public BufferedImage paintSubImage(BufferedImage img, int x, int y, int w, int h) { Graphics g = img.getGraphics(); g.setColor(Color.BLACK); g.fillRect(x,y,w,h); return img; } But I am not able to color it. Am I doing it wrong? 回答1: Given the fact that there is little or no context to go on, it's difficult to know exactly what's wrong. General rule of thumb though, if you create/open it, you should dispose/close it...

Printing a BufferedImage in Java

最后都变了- 提交于 2019-12-20 04:23:32
问题 Does anyone know how to print a BufferedImage in Java? 回答1: Printing is just like drawing on the screen, so eventually you get a Graphics object, and you just drawImage into it. 回答2: I'm not sure what you mean by print. Print on a printer? Print to standard out? Write to a file? You can check out this tutorial from sun. If you're looking to write to a file. Open in your favorite image tool and print from there. http://download.oracle.com/javase/tutorial/2d/images/saveimage.html If you're

Set BufferedImage to be a color in Java

拈花ヽ惹草 提交于 2019-12-19 05:04:49
问题 I need to create a rectangular BufferedImage with a specified background color, draw some pattern on the background and save it to file. I don't know how to create the background. I am using a nested loop: BufferedImage b_img = ... for every row for every column setRGB(r,g,b); But it's very slow when the image is large. How to set the color in a more efficient way? 回答1: Get the graphics object for the image, set the current paint to the desired colour, then call fillRect(0,0,width,height) .

Serializing an object that includes BufferedImages

痞子三分冷 提交于 2019-12-19 04:49:13
问题 As the title suggests, I'm trying to save to file an object that contains (among other variables, Strings, etc) a few BufferedImages. I found this: How to serialize an object that includes BufferedImages And it works like a charm, but with a small setback: it works well if your object contains only ONE image. I've been struggling to get his solution to work with more than one image (which in theory should work) but each time I read the file in, I get my object back, I get the correct number

Java colour detection

牧云@^-^@ 提交于 2019-12-18 13:35:58
问题 Im looking to implement a feature in Java which reads an image and is able to detect where there are shades of red, blue, green, yellow, etc. as part of a satellite image analysis program. So for example in a standard satellite image, blue would be water so I would like the program to read how many pixels are blue and then it could say x% of the image is water. I know it would be possible using a whole load of logic statements by reading the RGB value of each pixel but is there an easier way

How can you produce sharp paint results when rotating a BufferedImage?

帅比萌擦擦* 提交于 2019-12-18 11:09:50
问题 One attempted approach was to use TexturePaint and g.fillRect() to paint the image. This however requires you to create a new TexturePaint and Rectangle2D object each time you paint an image, which isn't ideal - and doesn't help anyway. When I use g.drawImage(BufferedImage,...) , the rotated images appear to be blurred/soft. I'm familiar with RenderingHints and double-buffering (which is what I'm doing, I think), I just find it difficult to believe that you can't easily and efficiently rotate

Java - Sending an object that points to a BufferedImage through a Socket

独自空忆成欢 提交于 2019-12-18 09:54:07
问题 Me and a group of friends are working on a project in Java, and we need some help regarding sending objects through sockets. So far, we have achieved to send simple objects (ints, strings and whatnot) through sockets, using ObjectOutputStream and ObjectInputStream . However, we ran into a huge problem today (huge for us, anyway ^^) We have a tree structure, that we need to send from one PC to another. The problem is that, within each node of that tree, we have a reference to a BufferedImage

Writing an animated gif from BufferedImages

半城伤御伤魂 提交于 2019-12-18 09:13:32
问题 I have a program that loads a spritesheet, creates BufferedImages of each frame on the sheet, and writes it to an animated gif. Using the class provided by Elliot Kroo on Creating animated GIF with ImageIO?, I was able to successfully output a file. However, the gif doesn't animate quite right. The sheet I provided was a .png with a transparent background, so every subsequent frame is just put on top of the last frames, with differences showing through the transparent background (Example).

How to add 20 pixels of white at the top of an existing image file?

北战南征 提交于 2019-12-18 08:22:51
问题 I have an image of size w by h . In Java, I need to create an image that is size w by h+20 where the top w by 20 pixels is white, and the rest of the image is the same as the original image. Essentially I want to know how I can add 20 pixels of white to the top of an existing buffered image. So it would be something like: public static void main (String[] args) { BufferedImage originalImage = [the original image with a specific file path]; ...code to create a new image 20 pixels higher... ..