bufferedimage

Convert RGB values to Integer

依然范特西╮ 提交于 2019-12-17 03:55:10
问题 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

Convert each animated GIF frame to a separate BufferedImage

谁说我不能喝 提交于 2019-12-17 03:16:06
问题 I want to be able to take an animated GIF as input, count the frames (and perhaps other metadata), and convert each to a BufferedImage . How can I do this? 回答1: If you want all the frames to be the same size (for optimized GIFs) try something like this: try { String[] imageatt = new String[]{ "imageLeftPosition", "imageTopPosition", "imageWidth", "imageHeight" }; ImageReader reader = (ImageReader)ImageIO.getImageReadersByFormatName("gif").next(); ImageInputStream ciis = ImageIO

Rotate BufferedImage Inside JPanel

◇◆丶佛笑我妖孽 提交于 2019-12-17 02:51:39
问题 I am trying to rotate a BufferedImage and display it inside a JLabel (which is inside a JPanel ). The current result produces a white square rotated 10 degrees against a black background, but the image is not present inside the square. I know myPicture is not blank, since myPicture itself displays properly inside the JPanel when not rotated. Here is the code: int w = myPicture.getWidth(); int h = myPicture.getHeight(); BufferedImage newImage = new BufferedImage(w, h, myPicture.getType());

Program freezes during Thread.sleep() and with Timer

混江龙づ霸主 提交于 2019-12-17 02:26:29
问题 Original question: This method is supposed to change the image being displayed on a JFrame gradually into another image. However, without some way to slow it down, it just seems to change from one image to the new image. In order to slow it down, I put in a Thread.sleep(1000) so the changes wouldn't happen instantly. However, with this line in there, my program freezes completely. No error message, no nothing. Can anyone please help me out? Suggest a better method to slow it down, or how this

How do I convert a InputStream to BufferedImage in Java/Groovy?

浪子不回头ぞ 提交于 2019-12-14 03:39:56
问题 Yes, I'm that stupid. I'm trying to stick some groovy code together from various cookbook recipes, and I can't get from an InputStream to BufferedImage in Java/Groovy. Google is not being my friend at present. 回答1: BufferedImage imBuff = ImageIO.read(object.getInputStream()); Should work... 来源: https://stackoverflow.com/questions/6464432/how-do-i-convert-a-inputstream-to-bufferedimage-in-java-groovy

Why does my paintComponent doesn't work?

我与影子孤独终老i 提交于 2019-12-14 03:18:04
问题 I think that the reason why my paintComponent is not working because I placed the image as a JLabel in a JPanel. I want to use drawRect to draw a rectangle when I click using the MouseListener. My image is a BufferedImage from JFileChooser JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES); if (fileChooser.showOpenDialog(panelPic) == JFileChooser.APPROVE_OPTION) { try { pic = ImageIO.read(fileChooser.getSelectedFile()); /

Move BufferedImage with Keys

柔情痞子 提交于 2019-12-14 03:15:11
问题 I have a background image on my 2D game, and I would like to know how I could move this image around with keys? I was trying things like: background.getX() + 3; But that wouldn't work as getX() isn't applicable for BufferedImages. How can I do this? 回答1: You're going to need two things. You're going to need to know the position of the image. A simple Point object should suffice. This tells you where to draw the image... Some where to catch key board events. For this I would suggest the key

Strange BufferedImage behaviour with 4bits palette

為{幸葍}努か 提交于 2019-12-14 02:33:12
问题 [See related] The following code opens a tiny PNG image, with a 4-bits palette and transparency (TRNS chunk) and prints the value of the pixels (1,1) and (1,2). Then it converts the image from the automatic type to TYPE_4BYTE_ABGR and prints the same pixels values. public static void images() throws IOException { File png = new File("c:\\temp\\04ptx.png"); BufferedImage bi1 = ImageIO.read(png); System.out.printf("%s is TYPE_BYTE_BINARY? %s (%d)\n",png, String.valueOf(BufferedImage.TYPE_BYTE

BufferedImage in JFrame doesnt Show up

烂漫一生 提交于 2019-12-13 18:43:42
问题 trying to get an image to print into a window. Everything runs without errors, and it also works if I replace the drawImage with another graphics class. However, the window is missing the image, and i'm not sure why. Again, the JFrame stuff and Graphics work fine with drawing other graphics, but only doesn't draw the image here. Thanks. import javax.swing.JApplet; import javax.swing.JFrame; import javax.imageio.*; import javax.imageio.stream.*; import java.awt.*; import java.awt.image.*;

Display a big number of images into a grid

会有一股神秘感。 提交于 2019-12-13 17:16:09
问题 I have an application, in which I want to displaying a number of image components. Each item of this will be a custom jcomponent which will has the image in a BufferedImage object to draw it in paintcomponents(Graphics g) overrided method. I will also use a JPanel for the grid with a gridlayout or flowlayout for place the custom image jcomponents , also the grid's layout will be inside an JscrollPane . My question is what happens, when the number of the images I must to put into the grid will