bufferedimage

Convert a Graphics2D to an Image or BufferedImage

耗尽温柔 提交于 2019-11-26 21:12:34
问题 I have a little problem here. I have an applet, where user can "draw" inside it. To do that, I use the java.awt.Graphics2D. But, how can I do to save the user draw image as a JPEG image, or at least, convert it to a BufferedImage or something? I don't know how to do that. Thanks. 回答1: Have them draw directly in a BufferedImage by way of it's Graphics2D object which you can get via getGraphics(). Then use ImageIO.write(...) to output the image to whatever file type you desire (and that's

How to load BufferedImage in android?

二次信任 提交于 2019-11-26 21:06:30
I want to load BufferedImage in my application. For that I am using ImageIO but I am getting java.lang.NoClassDefFoundError : BufferedImage tgtImg = loadImage("ImageD2.jpg"); public static BufferedImage loadImage(String ref) { BufferedImage bimg = null; try { bimg = ImageIO.read(new File(ref)); } catch (Exception e) { e.printStackTrace(); } return bimg; } but i am getting exception: 03-15 18:05:22.051: ERROR/AndroidRuntime(437): java.lang.NoClassDefFoundError: javax.imageio.ImageIO ImageIO is not supported in Android SDK Could you achieve the same thing with Bitmap and BitmapFactory ?? like so

Reading an image in Netbeans

北慕城南 提交于 2019-11-26 21:05:08
问题 I have an image file in my project. The hierarchy looks like this: I'm trying to read Manling.png into Manling.java using this code: public BufferedImage sprite; public Manling() { try { File file = new File("resources/Manling.png"); sprite = ImageIO.read(file); } catch (IOException e) {} System.out.println(sprite.toString()); //This line is to test if it works } I always get a NullPointerException on the println statement, so I assume the path is wrong. I've tried moving the image to

Java: BufferedImage to byte array and back

醉酒当歌 提交于 2019-11-26 20:28:36
I see that a number of people have had a similar problem, however I'm yet to try find exactly what I'm looking for. So, I have a method which reads an input image and converts it to a byte array: File imgPath = new File(ImageName); BufferedImage bufferedImage = ImageIO.read(imgPath); WritableRaster raster = bufferedImage .getRaster(); DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); What I now want to do is convert it back into a BufferedImage (I have an application for which I need this functionality). Note that "test" is the byte array. BufferedImage img = ImageIO.read(new

How to resize the buffered image n graphics 2d in java?

亡梦爱人 提交于 2019-11-26 20:27:56
问题 int width = 175; Graphics2D gb = (Graphics2D) g; bufferedimage = (BufferedImage) createImage(width, width); Graphics2D graphics = bufferedimage.createGraphics(); graphics.setColor(/*this.getBackground()*/Color.red); graphics.fillRect(0, 0, width, width); hi i have the the buffered with big size...i have to resize the bufferd image...plz can u anyone help me? 回答1: public BufferedImage scaleImage(BufferedImage img, int width, int height, Color background) { int imgWidth = img.getWidth(); int

Get RGB of a BufferedImage

那年仲夏 提交于 2019-11-26 20:13:26
问题 Can anybody explain how to get an array of rgb value from a BufferedImage? I have a grey scale image in a BufferedImage and need to extract an array of 0 to 255 values that describe the image. I know the BufferedImage is correct because I can save it to PNG. However, if I use int[] dataBuffInt = ((DataBufferInt) heightMap.getDataBuffer()).getData(); I get a bunch of huge negative numbers. I have searched for a while and seen some references to shifting some values (post) but don't really

Drawing a Component to BufferedImage causes display corruption

时光毁灭记忆、已成空白 提交于 2019-11-26 19:11:41
I am using the JScrollNavigator component described here , in order to provide a navigation window onto a large "canvas-like" CAD component I have embedded within a JScrollPane . I have tried to adapt the JScrollNavigator to draw a thumbnail image of the canvas to provide some additional context to the user. However, the action of doing this causes the rendering of my application's main frame to become corrupted. Specifically, it is the action of calling paint(Graphics) on the viewport component (i.e. my main canvas), passing in the Graphics object created by the BufferedImage that causes

How to serialize an object that includes BufferedImages

梦想的初衷 提交于 2019-11-26 18:58:58
I'm trying to create a simple image editing program in java. I made an ImageCanvas object that has all the information about the image that is being edited (some basic properties, list of effects being applied, a list of BufferedImage layers, etc.) and I wanted a simple way to save it to disk so it could be opened again later. I figured that using Java's defualt Serializable interface might be exactly what I was looking for and I could just write the entire object to file and read it back into memory again at a later time. However, ImageCanvas includes an ArrayList<BufferedImage> , and

Java BufferedImage getting red, green and blue individually

a 夏天 提交于 2019-11-26 18:39:00
The getRGB() method returns a single int. How can I get individually the red, green and blue colors all as the values between 0 and 255? Java's Color class can do the conversion: Color c = new Color(image.getRGB()); int red = c.getRed(); int green = c.getGreen(); int blue = c.getBlue(); A pixel is represented by a 4-byte (32 bit) integer, like so: 00000000 00000000 00000000 11111111 ^ Alpha ^Red ^Green ^Blue So, to get the individual color components, you just need a bit of binary arithmetic: int rgb = getRGB(...); int red = (rgb >> 16) & 0x000000FF; int green = (rgb >>8 ) & 0x000000FF; int

Convert RGB values to Integer

断了今生、忘了曾经 提交于 2019-11-26 18:28:51
So in a BufferedImage , you receive a single integer that has the RGB values represented in it. So far I use the following to get the RGB values from it: // rgbs is an array of integers, every single integer represents the // RGB values combined in some way int r = (int) ((Math.pow(256,3) + rgbs[k]) / 65536); int g = (int) (((Math.pow(256,3) + rgbs[k]) / 256 ) % 256 ); int b = (int) ((Math.pow(256,3) + rgbs[k]) % 256); And so far, it works. What I need to do is figure out how to get an integer so I can use BufferedImage.setRGB() , because that takes the same type of data it gave me. I think