bufferedimage

Serializing/Deserializing buffered images

爱⌒轻易说出口 提交于 2019-12-13 03:16:47
问题 I have a collection of buffered images that I want to serialize and then deserialize. For example I have an arrayList full of buffered images which are iterated through and written to a ObjectOutputStream for (BufferedImages i : images{ ImageIO.write(i,"png",ImageIO.createImageOutputStream(output)); } When I go to re-serialize the images, I tried to use BufferedImage image =ImageIO.read(ImageIO.createImageInputStream(input)); but it only reads in one image. Whats the correct way to re

Convert byte array of data type TYPE_4BYTE_ABGR to BufferedImage

狂风中的少年 提交于 2019-12-13 01:48:14
问题 I have a byte array with type TYPE_4BYTE_ABGR, and I know its width and height, I want to change it to BufferedImage, any ideas? 回答1: Might not be very efficient, but a BufferedImage can be converted to another type this way: public static BufferedImage convertToType(BufferedImage image, int type) { BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), type); Graphics2D graphics = newImage.createGraphics(); graphics.drawImage(image, 0, 0, null); graphics.dispose();

Drawing Graphics is too slow

ぃ、小莉子 提交于 2019-12-12 15:42:43
问题 So, I have this project, and you can draw images in it. I wanted people to be able to draw on it, but at first it was too slow when I was using repaint() So i used the repaint(Rectangle r) tool. It's better, but still not the speed i was looking for. Here is the code: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class DrawingPad extends JPanel implements MouseListener,MouseMotionListener,ListSelectionListener{ public Color[][] picture =

BufferedImage.getGraphics().drawImage() alters pixels values

隐身守侯 提交于 2019-12-12 14:11:30
问题 (This is a followup to a previous question) The standard recommended way of transforming a BufferedImage from one type to another, or to make a copy, is to use getGraphics().drawImage() (example). To my surprise, I've found that this procedure does not leave the pixel value unaltered, even even when both the source and target images are both of the same type! The issue shows up when there is some transparency. Example with a single pixel ARGB image: public static void imagesTestBiIssue()

Java Buffered Image RescaleOp Transparency Issue

青春壹個敷衍的年華 提交于 2019-12-12 12:48:36
问题 I seem to be having an issue where I create a BufferedImage which has transparent pixels like this: BufferedImage buff = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB); and it works fine until I filter it through the RescaleOp to darken it. When I do this, the image disappears. Here is my complete code just so you can see how I am setting this up: BufferedImage buff = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);

Stripping Alpha Channel from Images

人走茶凉 提交于 2019-12-12 10:49:33
问题 I want to strip the alpha channel (transparent background) from PNGs, and then write them as JPEG images. More correctly, I'd like to make the transparent pixels white. I've tried two techniques, both of which fail in different ways: Approach 1: BufferedImage rgbCopy = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D graphics = rgbCopy.createGraphics(); graphics.drawImage(inputImage, 0, 0, Color.WHITE, null); graphics.dispose(); return

Java Images take up too much memory

白昼怎懂夜的黑 提交于 2019-12-12 10:21:42
问题 I have a program that uses a lot of images. It loads alot of images from file, and stores them so they are only loaded once. It also creates multiple BufferedImages, about 400x400, there would be no more than 10 of these. The images from file total around 6MB. Each BufferedImage should be approx 400x400x4=640KB. Yet, the memory usage is 500MB! Some of this will be for the rest of the program, but I'm pretty sure that the images are taking up most of the space. Does anyone know what to do

Add image to panel not using swings [closed]

余生颓废 提交于 2019-12-12 06:46:12
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . how to we add bitmap image in panel and then get the graphics that the image is using and tell the panel to draw a line using the same graphics inside the image. 回答1: Basic painting is done by a Swing components

How to tint an ImageIcon [duplicate]

旧巷老猫 提交于 2019-12-12 06:35:09
问题 This question already has an answer here : How to draw a BufferedImage with a color tint (1 answer) Closed 4 years ago . How would I tint the icon that is passed through here to be a different color? Say I wanted to take a white image and make it a bit darker. I have looked into BufferedImages and such but I can't seem to find anything that will fit into the setup that I am using. I should also note that I am drawing the images onto a JLabel if that makes a difference. Here is the source that

Java: Loading png images without indexing (as BufferedImage.TYPE_4BYTE_ABGR), using javax.imageio.ImageIO.read()

风流意气都作罢 提交于 2019-12-12 05:59:05
问题 I am trying to load a PNG image using the javax.imageio.ImageIO.read() method. However, I want the resulting type to be "BufferedImage.TYPE_4BYTE_ABGR", but it ends up as an indexed image ("BufferedImage.TYPE_BYTE_INDEXED"). Is there any way to load an image as unindexed, when the original image is indexed? There are about 120 images, so it would take too long to make them all unindexed by hand. 回答1: If you're not opposed to using JAI, you can create a rendering chain for the RenderedImage