bufferedimage

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

不打扰是莪最后的温柔 提交于 2019-11-30 01:38:35
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 an image in Java that produces sharp results. Code for using TexturePaint looks something like this.

Clear a transparent BufferedImage as fast as possible

帅比萌擦擦* 提交于 2019-11-29 18:24:06
问题 I have a transparent BufferedImage created with the following code(not relevant how it is created, I think): GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); Rectangle screen = transformationContext.getScreen(); // Create an image that supports transparent pixels return gc.createCompatibleImage((int) screen.getWidth(), (int) screen.getHeight(), Transparency

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

こ雲淡風輕ζ 提交于 2019-11-29 18:05:48
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 and it's not serializable. We have been researching a lot today, and we found out that we can use

How to disable java.awt.Graphics.fillRect(int x, int y, int width, int height)'s effect?

醉酒当歌 提交于 2019-11-29 16:46:39
It's the original image: I use java.awt.Graphics.fillRect(int x, int y, int width, int height) to add a coloured rectangle on the image. Graphics imageGraphics = image.createGraphics(); Color color = new Color(0,0,0,100); imageGraphics.setColor(color); imageGraphics.fillRect(0, 0, 800, 600); So the image has been inverted and looks like this: After that,I want to clear the black transparent rectangle partly and show the original image. imageGraphics.clearRect(100,100,100,100); But the effect is like this: What my requirement is: I want to know why it doesn't work and is there any other way to

How do I speed up this swing animation?

[亡魂溺海] 提交于 2019-11-29 16:21:12
I am drawing an animation onto a swing JPanel. The 1024x1024 screen is divided up into 2000 pieces which cover the screen exactly (no overlap). each piece is a very small piece of the screen (1/2000'th of it). The animation draws one piece every millisecond by changing the pixels in the buffered image and calling reaint(). So at the entire screen changes every 2 seconds. The animation is run in a java.util.Timer task. The buffered image is not accelerated and is not volatile. I set it's priority to 1. The frame root pane is optimized. Both the front and back buffer are accelerated but not

Why is my gif image sent from servlet not animating?

冷暖自知 提交于 2019-11-29 16:09:24
I have this following code in my servlet response.setContentType("image/gif"); String filepath = "PATH//TO//GIF.gif"; OutputStream out = response.getOutputStream(); File f = new File(filepath); BufferedImage bi = ImageIO.read(f); ImageIO.write(bi, "gif", out); out.close(); This code is just returning first frame of the image. How to achieve returning full GIF image ? haraldK Your GIF does not animate, because you are sending only the first frame to the client. :-) Actually, you are, because ImageIO.read reads only the first frame (and a BufferedImage can only contain a single frame/image). You

drawing your own buffered image on frame

我怕爱的太早我们不能终老 提交于 2019-11-29 15:54:52
I have a buffered image with the sizes of my frame: public BufferedImage img; public static int WIDTH = 800; public static int HEIGHT = 600; img=new BufferedImage(WIDTH, HEIGHT,BufferedImage.TYPE_INT_RGB); How can I draw it so I can see just a black image filling the frame? without using Canvas I want to use only the drawImage function from graphics without using the paint or paintComponent functions If it is possible, how can i assign an 1D array [WIDTH*HEIGHT] to that image? SIMPLY: I want to create an image ,convert the values from an array to pixels (0=black,999999999=lightblue etc.) and

Java Compare one BufferedImage to Another

霸气de小男生 提交于 2019-11-29 15:04:05
I need to compare two buffered images to see if they are the exact same. Simply saying if that equals that doesn't work. My current method is { Raster var1 = Img1.getData(); Raster var2 = Img2.getData(); int Data1 = (var1.getDataBuffer()).getSize(); int Data2 = (var2.getDataBuffer()).getSize(); if (Data1 == Data2) { return true; } else { return false; } } But that doesn't really work. What other more reliable way is there? devrobf The obvious solution would be to compare, pixel by pixel, that they are the same. boolean bufferedImagesEqual(BufferedImage img1, BufferedImage img2) { if (img1

how can I convert an RGB image to CMYK and vice versa in Java?

依然范特西╮ 提交于 2019-11-29 14:13:51
our web app let users download dynamically generated images in different formats (bmp, png and jpeg). Some of our users download the images for printing, thus we would like to allow them to choose between RGB or CMYK. Is there a way to specify the color model when creating a RenderedImage/BufferedImage? If not, what is the default color model and how can I change it to another? Code snippets are welcome :) Thanks, Olivier. It appears that it's not simple and you'll have to either load up a color profile to do it or extend the colorspace to support CYMK. Some image formats doesn't allow CMYK

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

試著忘記壹切 提交于 2019-11-29 14:13:26
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... ...code to paint originalImage 20 pixels down on the new image ...code to save the new image... }