bufferedimage

Change contents of BufferedImage, then update JFrame to reflect it

牧云@^-^@ 提交于 2019-11-28 06:37:32
问题 I am trying to make a Mandelbrot Set renderer with a GUI where you can click and drag to zoom into a specific area. When run, it will do the initial calculations and rendering fine, but when you try to click and drag to zoom in, the console says it is doing the calculations, but the content of the JFrame is not updated. However, I'm not even positive that it is recalculating, because the initial calculation takes about 8 seconds but when you click/drag to zoom it takes about 6 ms. I have

Rotating BufferedImage changes its colors

别等时光非礼了梦想. 提交于 2019-11-28 06:25:30
问题 I'm trying to code a class to seam carve images in x and y direction. The x direction is working, and to reduce the y direction I thought about simply rotating the image 90° and run the same code over the already rescaled image (in x direction only) and after that, rotate it back to its initial state. I found something with AffineTransform and tried it. It actually produced a rotated image, but messed up the colors and I don't know why. This is all the code: import java.awt.image

Java- Convert bufferedimage to byte[] without writing to disk

≯℡__Kan透↙ 提交于 2019-11-28 05:53:15
I'm trying to send multiple images over a socket using java but I need a faster way to convert the images to a byte array so I can send them. I tried the following code but it wrote about 10,000 images to my C:\ drive. Is there a way to make this conversion without writing to disk? Thanks! ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); //ImageIO.setUseCache(false); ImageIO.write(bi.getImage(), "jpg", outputStream); byte[] imageBytes = outputStream.toByteArray(); This should work: byte[] imageBytes = ((DataBufferByte) bufferedImage.getData().getDataBuffer()).getData(); The

How to use TYPE_BYTE_GRAY to efficiently create a grayscale bufferedimage using AWT

懵懂的女人 提交于 2019-11-28 05:34:00
问题 I need to create a grayscale image from data in an nio ShortBuffer. I have a function that maps the data in the ShortBuffer to unsigned byte but is in an int (easily changed). The method I found uses an RGB plus transparency color model and appears to be quite inefficent. i have not been able to see how to apply the TYPE_BYTE_GRAY and modify the code. i'm new to Java. Here's my code: public void paintComponent(Graphics g) { final BufferedImage image; int[] iArray = {0, 0, 0, 255}; // pixel

Layer multiple BufferedImages on top of one another?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 05:33:53
问题 I have multiple transparent BufferedImage instances which I'd like to layer on top of each other (aka Photoshop layers) and bake into one BufferedImage output. How do I do this? 回答1: I would say the best bet would be to take the buffered images, and create an additional one in order to have an object to append to. Then simply use the Graphics.drawImage() to place them on top of each other. So something along these lines: BufferedImage a = ImageIO.read(new File(filePath, "a.png"));

GUI freezes when drawing Wave from animation on JPanel though i used Swing Timer

一个人想着一个人 提交于 2019-11-28 05:29:09
问题 plese look at my code snippets , wha is wrong with it , it frrezes GUI when the Swing timer stats which is repeteadly paints on the jpnael ?? class WaveformPanel extends JPanel { Timer graphTimer = null; AudioInfo helper = null; WaveformPanel() { setPreferredSize(new Dimension(200, 80)); setBorder(BorderFactory.createLineBorder(Color.BLACK)); graphTimer = new Timer(15, new TimerDrawing()); } /** * */ private static final long serialVersionUID = 969991141812736791L; protected final Color

Create a BufferedImage from file and make it TYPE_INT_ARGB

假装没事ソ 提交于 2019-11-28 04:56:15
I have a PNG file with transparency that is loaded and stored in a BufferedImage . I need this BufferedImage to be of TYPE_INT_ARGB . However, when I use getType() the returned value is 0 ( TYPE_CUSTOM ) instead of 2 ( TYPE_INT_ARGB ). This is how I load the .png : public File img = new File("imagen.png"); public BufferedImage buffImg = new BufferedImage(240, 240, BufferedImage.TYPE_INT_ARGB); try { buffImg = ImageIO.read(img ); } catch (IOException e) { } System.out.Println(buffImg.getType()); //Prints 0 instead of 2 How can I load the .png, save in the BufferedImage and make it TYPE_INT_ARGB

Is there a way to create one Gif image from multiple images in Java? [closed]

喜欢而已 提交于 2019-11-28 04:34:20
I am trying to set up a simple Java program that creates one single animated gif from multiple other images (jpg). Can anyone give me a hook on how to achieve this in Java? I already searched Google but couldn't find anything really helpful. Thank you guys! Here you have an example of a class that creates an animated gif from different images: Link The class provides these methods: class GifSequenceWriter { public GifSequenceWriter( ImageOutputStream outputStream, int imageType, int timeBetweenFramesMS, boolean loopContinuously); public void writeToSequence(RenderedImage img); public void

Can I create a BufferedImage from a JPanel without rendering in a JFrame?

99封情书 提交于 2019-11-28 03:03:19
问题 Is it possible to create a BufferedImage from a JPanel without first rendering it in a JFrame? I've searched everywhere I can think of and cannot find an answer. Can anyone help? Here is some sample code. If I don't un-comment the JFrame code, my BufferedImage is blank. test(){ // JFrame frame = new JFrame(); JPanel panel = new JPanel(); Dimension dim = new Dimension(50,50); panel.setMinimumSize(dim); panel.setMaximumSize(dim); panel.setPreferredSize(dim); JLabel label = new JLabel("hello");

Rendering BufferedImage in JTable cell

僤鯓⒐⒋嵵緔 提交于 2019-11-28 02:28:32
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? 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 with a JLabel that displays the Icon. In fact, I believe that the DefaultCellRenderer really is a JLabel,