bufferedimage

How to save a BufferedImage as a File

别来无恙 提交于 2019-11-27 03:07:53
I am using the imgscalr Java library to resize an image . The result of a resize() method call is a BufferedImage object. I now want to save this as a file (usually .jpg). How can I do that? I want to go from BufferedImage -> File but perhaps this is not the correct approach? File outputfile = new File("image.jpg"); ImageIO.write(bufferedImage, "jpg", outputfile); Raj Adroit You can save a BufferedImage object using write method of the javax.imageio.ImageIO class. The signature of the method is like this: public static boolean write(RenderedImage im, String formatName, File output) throws

How to check a uploaded file whether it is a image or other file?

假装没事ソ 提交于 2019-11-27 00:06:36
In my web application I have an image uploading module. I want to check the uploaded file whether it's an image file or any other file. I am using Java in server side. The image is read as BufferedImage in java and then I am writing it to disk with ImageIO.write() How shall I check the BufferedImage , whether it's really an image or something else? Any suggestions or links would be appreciated. BalusC I'm assuming that you're running this in a servlet context. If it's affordable to check the content type based on just the file extension, then use ServletContext#getMimeType() to get the mime

Rendering BufferedImage in JTable cell

a 夏天 提交于 2019-11-26 23:43:08
问题 I need to display a BufferedImage in one JTable column. I overwrote JTable method @Override public Class<?> getColumnClass(int column) { if (column == 1){ return BufferedImage.class; } return super.getColumnClass(column); } But I am still obtaining String representation of the object instead of image itself.Does anyone have idea what I am missing? 回答1: I'd populate the column that needs to show an image with ImageIcons and have the getColumnClass() method return Icon.class, and then render it

Convert short[] into a grayscale image

℡╲_俬逩灬. 提交于 2019-11-26 23:25:31
问题 I am writing a Buddhabrot fractal generator using aparapi. I got the OpenCL part of it to work, resulting in a single-dimension array that represents each pixel. I have the dimensions of the final image as final ints, and have written code to get the index of arbitrary points in that array. I want to save this as an image and I'm trying to use BufferedImage with TYPE_USHORT_GRAY. Here's what I have so far: BufferedImage image=new BufferedImage(VERTICAL_PIXELS, HORIZONTAL_PIXELS, BufferedImage

java.lang.IllegalArgumentException: input == null! when using ImageIO.read to load image as bufferedImage

我与影子孤独终老i 提交于 2019-11-26 23:11:06
This is a question that has been asked like 100 times on this site, but I have looked at all of them and even though they all were solved, none of the solutions worked for me. Here's what my code looks like: public Button1(Client client, String imgName) { this.client = client; try { this.icon = ImageIO.read(this.getClass().getResourceAsStream("/resources/" + imgName)); } catch (IOException e) { e.printStackTrace(); } When the code runs it results in the following error: Exception in thread "main" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source)

How to convert buffered image to image and vice-versa?

旧城冷巷雨未停 提交于 2019-11-26 23:01:29
问题 Actually i am working on a image editing software and now i want to convert the buffered-image i.e : BufferedImage buffer = ImageIO.read(new File(file)); to Image i.e in the format something like : Image image = ImageIO.read(new File(file)); Is it possible to so?? If yes, then how?? 回答1: BufferedImage is a(n) Image, so the implicit cast that you're doing in the second line is able to be compiled directly. If you knew an Image was really a BufferedImage, you would have to cast it explicitly

Part 2 - How do I get consistent rendering when scaling a JTextPane?

穿精又带淫゛_ 提交于 2019-11-26 22:07:38
问题 I submitted another version of this question and a sample program before: How do I get consistent rendering when scaling a JTextPane? Recapitulating the problem: I would like to allow users to zoom into or out of a non-editable JTextPane. Running the example program submitted in the earlier question, which simply scaled the Graphics object, resulted in inconsistent spacing between runs of bold text and non-bold text. The sample program below attempts to solve the problem by drawing the text

Printable prints BufferedImage with incorrect size

家住魔仙堡 提交于 2019-11-26 21:57:22
问题 So yeah what I am trying here is printing a BufferedImage, all works just fine until you see the outcome. The outcome is to big, the print is to large and doesn't it scales up everything when printing for some reason. I used ((MM * DPI)/25,4) to calculate the correct pixel length according to paper size from Millimeters but when I print it its to big. This is the code I wrote for it: package frik.main; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java

Null Pointer Exception on getGraphics()

淺唱寂寞╮ 提交于 2019-11-26 21:29:19
问题 my application looks like that, i am getting a null pointer exception at the draw() method, to be exact at g.drawImage(img, 0, 0, null) package com.ochs.game; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.JPanel; public class Game extends JPanel implements Runnable{ private static final long serialVersionUID = 8229934361462702491L; public static final int WIDTH = 320; public

Java - Image Rotation

ぃ、小莉子 提交于 2019-11-26 21:17:09
问题 I am trying to rotate image. I am using this Java code: BufferedImage oldImage = ImageIO.read(new FileInputStream("C:\\workspace\\test\\src\\10.JPG")); BufferedImage newImage = new BufferedImage(oldImage.getHeight(), oldImage.getWidth(), oldImage.getType()); Graphics2D graphics = (Graphics2D) newImage.getGraphics(); graphics.rotate(Math.toRadians(90), newImage.getWidth() / 2, newImage.getHeight() / 2); graphics.drawImage(oldImage, 0, 0, oldImage.getWidth(), oldImage.getHeight(), null);