bufferedimage

How can I display a BufferedImage in a JFrame?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 03:36:20
I want to display variations of the same image in the same JFrame, for example display an image in JFrame, then replace it with gray scale of the same image. ldog You will have to repaint the JFrame whenever you update the image. Here is what a simple google on the topic brings up: (I use those tutorials for all my Java coding) Java Tutorial: Drawing an Image Ian Will To build on camickr's solution (for the lazy like me who want quick code to copy/paste) here's a code illustration: JFrame frame = new JFrame(); frame.getContentPane().setLayout(new FlowLayout()); frame.getContentPane().add(new

Create an image from a non-visible AWT Component?

二次信任 提交于 2019-11-29 03:02:51
I'm trying to create an image (screen-shot) of a non-visible AWT component. I can't use the Robot classes' screen capture functionality because the component is not visible on the screen. Trying to use the following code: BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); component.paintAll(g); Works sometimes, but does not work if the component contains things such as a text box or button, or some sort of OpenGL / 3D component (these things are left out of the image!). How can I take a proper screenshot of the whole thing

How do I properly load a BufferedImage in java?

时光毁灭记忆、已成空白 提交于 2019-11-29 02:49:09
Okay, so I've been trying to load a BufferedImage using this code: URL url = this.getClass().getResource("test.png"); BufferedImage img = (BufferedImage) Toolkit.getDefaultToolkit().getImage(url); This gives me a type cast error when I run it though, so how do I properly load a BufferedImage? Use ImageIO.read() instead: BufferedImage img = ImageIO.read(url); BufferedImage img = null; try { img = ImageIO.read(new File("D:\\work\\files\\logo.jpg")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } 来源: https://stackoverflow.com/questions/601274/how-do-i-properly

Add BufferedImage to PDFBox document

妖精的绣舞 提交于 2019-11-28 23:57:37
In my current project, I try to add a BufferedImage to a PDFBox document. More specificly, I use an image from a JFreeChart . My code looks like this: public void exportToPDF(JFreeChart chart, String filePath){ PDDocument doc = null; PDPage page = null; PDXObjectImage ximage = null; try { doc = new PDDocument(); page = new PDPage(); doc.addPage(page); PDPageContentStream content = new PDPageContentStream(doc, page); BufferedImage image = chart.createBufferedImage(300, 300); ximage = new PDJpeg(doc, image); content.drawImage(ximage, 20, 20); content.close(); } catch(IOException ie) { } doc.save

How to read pixel color in a java BufferedImage with transparency

痴心易碎 提交于 2019-11-28 23:38:13
I am reading pixel color in a BufferedImage as follows: ..... InputStream is = new BufferedInputStream(conn.getInputStream()); BufferedImage image = ImageIO.read(is); int color = image.getRGB(x, y); int red = (colour & 0x00ff0000) >> 16; int green = (colour & 0x0000ff00) >> 8; int blue = colour & 0x000000ff; Now this works fine except for png's with transparency. I find that if x,y refer to a transparent pixel with no color, i still read a color, generally the same color as used elsewhere in the image. How do I detect that the pixel is actually transparent and not colored? Thanks int alpha =

Load Java Image inside package from a class in a different package

南楼画角 提交于 2019-11-28 23:25:32
I have a Java project called MyProject. I have a few different packages (keeping names simple for the purpose of this question), as follows: src/PackageA src/PackageA/PackageAa src/PackageA/PackageAa/PackageAaa src/PackageB src/PackageB/PackageBa src/PackageB/PackageBa/PackageBaa I have a class src/PackageA/PackageAa/PackageAaa/MyJavaFile.java And I have an image src/PackageB/PackageBa/PackageBaa/MyImage.png Inside of MyJavaFile.java , I would like to declare an Image oject of MyImage.png Image img = new Image(....what goes here?...) How can I do this? You could either call Class.getResource

Converting a series of BufferedImages to a video in Java?

孤街浪徒 提交于 2019-11-28 21:23:25
How would I convert an an array of BufferedImages into a video? I'm making a screen recorder. How would I compress the video afterward? You can use Xuggler (on Windows, Mac or Linux) to do this, and the following tutorials will show you exactly how to do it. In particular, see the (I'm not kidding) "How to Grow Some Balls" tutorial for a program that makes a video out of a series of BufferedImages (and some audio). You'll need the JMF (Java Media Framework) API for this. Sun has a code sample on the subject in the JMF documentation: Generating a Movie File from a List of (JPEG) Images . Update

Manipulate an image without deleting its EXIF data

情到浓时终转凉″ 提交于 2019-11-28 18:53:48
Using imageIO, I usually have the problem of transforming an image file, and after overwriting it, it loses all of its EXIF data. Is there any way to preserve it without first extracting it, caching it, and then resetting it? ImageIO do have this functionality itself, but instead of ImageIO.read you will need to use ImageReader: ImageReader reader = ImageIO.getImageReadersBySuffix("jpg").next(); (you may want to also check if such reader exists). Then you need to set the input: reader.setInput(ImageIO.createImageInputStream(your_imput_stream)); Now you may save your metadata: IIOMetadata

Fast loading and drawing of RGB data in BufferedImage

烂漫一生 提交于 2019-11-28 17:20:02
In some Java code running on Windows, I'm reading some large blocks of RGB data from disk and want to display this to screen as quickly as possible. The RGB data is 8 bits per channel without any alpha. Currently I have code like the following to create the BufferedImage. BufferedImage getBufferedImage(File file, int width, int height) { byte[] rgbData = readRGBFromFile(file); WritableRaster raster = Raster.createInterleavedRaster( rgbData, width, height, width * 3, // scanlineStride 3, // pixelStride new int[]{0, 1, 2}, // bandOffsets null); ColorModel colorModel = new ComponentColorModel(

Rotating an Image object

半世苍凉 提交于 2019-11-28 14:11:43
I have a method getImage() that needs to rotate an Image , store it in a new variable, then return that new Image . Here is my attempt, the image appears to be empty or something. It just does not show up on the screen: public Image getImage() { buffImage.createGraphics().rotate(direction); return buffImage; } When I take out the buffImage.createGraphics().rotate(direction); the image draws on the screen just fine with no problems but of course, not rotated. MadProgrammer So, based on the example in this answer , you should be able to devise a rotation method which can rotate a source image by