bufferedimage

Clear portion of graphics with underlying image

你离开我真会死。 提交于 2019-11-28 11:43:11
问题 I'm making a 'game' of sorts where the player has to click on an image bouncing around the screen. The catch is that the screen is in darkness and the mouse cursor is a 'flashlight' which 'light up' a small circle around it. I have a JFrame in one class consisting of: public class GameFrame { public static void main(String[] args) throws IOException { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); JFrame jf = new JFrame("Flashlight Game"); jf.setVisible(true); jf

How to increase the resolution of image in PDF renderer?

烂漫一生 提交于 2019-11-28 11:25:08
I want to increase the resolution of a image. I used PDFRenderer-0.9.0 jar . It is downloaded from java.net for converting PDF pages to images. I want to Convert 46_2.pdf PDF file to image . The converted 46_2.png image is small with dimensions 612 x 792 [ width x height ] , So I want to increase the image dimensions to 1200 x 1400 [ width x height] . I tried previously PdfBox for converting PDF page into PNG image file. There is a problem only page is converted but text is missing . So I tried PdfRenderer for image conversion. Code: package com.pdfrenderer.examples; import java.awt.Graphics2D

Out of memory problem saving large BufferedImage

大兔子大兔子 提交于 2019-11-28 11:21:41
I have a problem saving large (f.e. 12 000 x 9 000 ) images. I'm developing a graphical editing software ( something like simple Photoshop ) and The user obviously has to have to ability to save the image. Lets say I would like to save the image as .png. Does JAVA always need to use the BufferedImage for saving drawn stuff ? I know the equation for size of the image is: Xsize * Ysize * 4 ( red, green, blue, alpha ) So in this case we get over 400 MB. I know I could save the image in parts ( tiles ) but the user would have to merge them somehow anyway. Is there any other way to save such a

Sending a screenshot (bufferedImage) over a socket in java

早过忘川 提交于 2019-11-28 11:17:56
I am sending a bufferedImage over a socket and I am using the example found in this post: Sender BufferedImage image = ....; ImageIO.write(image, "PNG", socket.getOutputStream()); Receiver BufferedImage image = ImageIO.read(socket.getInputStream()); It works - IF, and ONLY IF, I close the sender's outputStream after this line: ImageIO.write(image, "PNG", socket.getOutputStream()); Is there anything I can do apart from closing the outputStream? Also, is there anything else I can do to avoid using ImageIO altogether? It seems to take ages to do anything. Also note that reading or writing to the

How can I import java.awt.image.BufferedImage in Android Studio

耗尽温柔 提交于 2019-11-28 10:08:01
I need my android app to recognize BufferedImage and I am using Android Studio. I've seen that there is a way to import JRE library system in Eclipse but I am having trouble doing so in Android Studio. Any ideas? Thanks! ESala You can't. The AWT package is not supported in Android, you need to change your implementation to use the Android classes. See these similar questions: Porting AWT graphics code to Android How to add java AWT image package in Android Using AWT with Android 来源: https://stackoverflow.com/questions/33210065/how-can-i-import-java-awt-image-bufferedimage-in-android-studio

Why is my gif image sent from servlet not animating?

谁说胖子不能爱 提交于 2019-11-28 10:07:45
问题 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 ? 回答1: Your GIF does not animate, because you are sending only the first frame to the client. :-) Actually, you are, because

Java rotating an ImageBuffer fails

不羁岁月 提交于 2019-11-28 09:32:38
问题 I am trying to rotate an instance of a BufferImage named pic when I try this it resizes and skews and crops the image, any advice to get it to work properly public void rotate(double rads){ AffineTransform tx = new AffineTransform(); tx.rotate(rads,pic.getWidth()/2,pic.getHeight()/2); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); pic = op.filter(pic, null); } When I have it rotate 90˚ it works fine so I'm wondering if the problem is that it is the shape of

Java Compare one BufferedImage to Another

怎甘沉沦 提交于 2019-11-28 08:57:32
问题 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? 回答1: The obvious solution would be to compare, pixel by pixel, that

Drawing multiple lines in a BufferedImage

柔情痞子 提交于 2019-11-28 07:35:14
问题 I am trying to draw horizontal and vertical lines on a bufferedimage. It should end up looking like a grid of cells. But when I run the code, I see only two lines: the leftmost line and the topmost line (ie. a line from 0,0 to 0,height of image & 0,0 to width of image,0) Heres the code snippet: BufferedImage mazeImage = new BufferedImage(imgDim.width, imgDim.height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = mazeImage.createGraphics(); g2d.setBackground(Color.WHITE); g2d.fillRect(0, 0,

Load image from a filepath via BufferedImage

对着背影说爱祢 提交于 2019-11-28 07:14:46
问题 I have a problem with Java application, particular in loading a image from a location in my computer. Following this post I used a BufferedImage and a InputFileStream to load an image on my computer. First, I put the image ( pic2.jpg ) into the source code and that is working. However, if I put the image to another place (let's say C:\\ImageTest\pic2.jpg ), Java IDE show me an IllegalArgumentException return ImageIO.read(in); here is the code: public class MiddlePanel extends JPanel { private