bufferedimage

reading black/white image in java with TYPE_USHORT_GRAY

岁酱吖の 提交于 2021-02-17 02:50:11
问题 I have the following code to read a black-white picture in java. imageg = ImageIO.read(new File(path)); BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_USHORT_GRAY); Graphics g = bufferedImage.createGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); int w = img.getWidth(); int h = img.getHeight(); int[][] array = new int[w][h]; for (int j = 0; j < w; j++) { for (int k = 0; k < h; k++) { array[j][k] = img.getRGB(j, k);

Efficiently extracting RGBA buffer from BufferedImage

我是研究僧i 提交于 2021-02-11 17:19:32
问题 I've been trying to load in bufferedImages in java as IntBuffers. However, one problem I've come across is getting the pixel data from an image with semi or complete transparency. Java only seems to allow you to get the RGB value, which in my case is a problem because any pixels that should be transparent are rendered completely opaque. After about a few hours of searching I came across this way of getting the RGBA values... Color color = new Color(image.getRGB(x, y), true); Although it does

Using IntBuffer for BufferedImage

丶灬走出姿态 提交于 2021-02-10 13:15:30
问题 As the title aleady says, it want to create a BufferedImage that is backed by a specific (already existing) IntBuffer. Up to this point, I have the following code: final IntBuffer buf = ...; DataBuffer dbuf = new DataBuffer(DataBuffer.TYPE_INT,size) { public void setElem(int bank, int i, int val) { buf.put(i,val); } public int getElem(int bank, int i) { return buf.get(i); } }; ColorModel cm = ColorModel.getRGBdefault(); SampleModel sm = cm.createCompatibleSampleModel(dim.width,dim.height);

Using IntBuffer for BufferedImage

故事扮演 提交于 2021-02-10 13:15:03
问题 As the title aleady says, it want to create a BufferedImage that is backed by a specific (already existing) IntBuffer. Up to this point, I have the following code: final IntBuffer buf = ...; DataBuffer dbuf = new DataBuffer(DataBuffer.TYPE_INT,size) { public void setElem(int bank, int i, int val) { buf.put(i,val); } public int getElem(int bank, int i) { return buf.get(i); } }; ColorModel cm = ColorModel.getRGBdefault(); SampleModel sm = cm.createCompatibleSampleModel(dim.width,dim.height);

Why use ImageIO can't get BufferedImage from URL

▼魔方 西西 提交于 2021-02-09 11:42:50
问题 imageURL: https://fbexternal-a.akamaihd.net/safe_image.php?d=AQBB77GLfY75FNWL&w=720&h=2048&url=http%3A%2F%2Fwww.facebook.com%2Fads%2Fimage%2F%3Fd%3DAQI0duFYFcmydWNutbwmSk2DfOmHcDrhPfsMJTUoEObbWkVzYUtrHgCuN_LFrWcPRzJi6jPgbn80oFs0Kj_WrdROjdnJkjbnS5-UJv9l9cJyhKCWS-lr-MXlc263Ul3Txe-VFqXfRrA6BOjt4DF-Sww2&ext=best URL url = new URL(imageURL); BufferedImage image = ImageIO.read(url); or URL url = new URL(imageURL); BufferedImage image = ImageIO.read(url.openStream()); the result image is null? why?

Java ImageWriter BufferedImage to GIF

眉间皱痕 提交于 2021-02-08 05:23:46
问题 I hope you guys can help me with this one. I'm not sure if it is a bug in Java or if I'm doing something wrong, but I'll go with the latter. I want to turn a BufferedImage into a GIF image. I then wish to keep the GIF in the memory in the form of a byte array. (I do not want to save the file to disk) The program should capture a screen segment (just to create a quick image) and turn it into a GIF byte array using ImageIO ImageWriter and ByteArrayOutputStream. The code below will show you the

Java ImageWriter BufferedImage to GIF

半城伤御伤魂 提交于 2021-02-08 05:23:07
问题 I hope you guys can help me with this one. I'm not sure if it is a bug in Java or if I'm doing something wrong, but I'll go with the latter. I want to turn a BufferedImage into a GIF image. I then wish to keep the GIF in the memory in the form of a byte array. (I do not want to save the file to disk) The program should capture a screen segment (just to create a quick image) and turn it into a GIF byte array using ImageIO ImageWriter and ByteArrayOutputStream. The code below will show you the

Properly drawing over an image

空扰寡人 提交于 2021-02-04 19:49:08
问题 I'm creating a small image editor and right now i'm trying to give the user the chance of drawing over the image by dragging the mouse (like pencil tool in MS Paint does). I'm having some difficulties since, when i move the cursor too fast, the application can't draw all the pixels which should be colored, just a little number is correctly colored. I tried two solutions to add the colored pixels: at first i created a list where i stored all the points added when mouseDragged was called. After

How to convert JLabel.getIcon() to BufferedImage

大兔子大兔子 提交于 2021-01-28 01:35:03
问题 I have a JLabel that contains only an icon, and I can get the Icon with label1.getIcon(), but I can't figure out how to convert that Icon into a BufferedImage. Just FYI, I'm not talking about ImageIcon, only Icon. Also, I have seen the question at How to convert Icon from JLabel into BufferedImage?, but I can't seem to figure it out. As always, any examples or explanation are much appreciated. Thanks! 回答1: You may try this. // Get the icon Icon ico = label1.getIcon(); // Create a buffered

Java create BufferedImage with float precision

六眼飞鱼酱① 提交于 2021-01-24 02:37:46
问题 I created a map editor in Java. The problem is, I have steps for every byte value, so the map isn't smooth. Is it possible to change the BufferedImage raster data to float data and draw in float precision on it? 回答1: To answer your question, yes, you can create a BufferedImage with float precision. It is however a little unclear if this will help you solve your problem. In any case, here's working example code for creating a BufferedImage with float precision: public class FloatImage { public