bufferedimage

Strange PNG errors: Bad length for IHDR chunk

时间秒杀一切 提交于 2019-11-27 06:27:05
问题 Heres the error: Exception in thread "main" javax.imageio.IIOException: I/O error reading PNG header! at com.sun.imageio.plugins.png.PNGImageReader.readHeader(PNGImageReader.java:307) at com.sun.imageio.plugins.png.PNGImageReader.readMetadata(PNGImageReader.java:637) at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1212) at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1560) at javax.imageio.ImageIO.read(ImageIO.java:1422) at javax.imageio

Sending a screenshot (bufferedImage) over a socket in java

落花浮王杯 提交于 2019-11-27 06:10:14
问题 I am sending a bufferedImage over a socket and I am using the example found in this post: Sender BufferedImage image = ....; ImageIO.write(image, "PNG", socket.getOutputStream()); Receiver BufferedImage image = ImageIO.read(socket.getInputStream()); It works - IF, and ONLY IF, I close the sender's outputStream after this line: ImageIO.write(image, "PNG", socket.getOutputStream()); Is there anything I can do apart from closing the outputStream? Also, is there anything else I can do to avoid

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

一世执手 提交于 2019-11-27 05:36:52
问题 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(); 回答1: This

Load a sprites image in java

北慕城南 提交于 2019-11-27 05:31:58
I want to ask if why am getting error loading any sprite images into the object here is how I get the image in. import java.awt.image.BufferedImage; import java.io.IOException; public class SpriteSheet { public BufferedImage sprite; public BufferedImage[] sprites; int width; int height; int rows; int columns; public SpriteSheet(int width, int height, int rows, int columns, BufferedImage ss) throws IOException { this.width = width; this.height = height; this.rows = rows; this.columns = columns; this.sprite = ss; for(int i = 0; i < rows; i++) { for(int j = 0; j < columns; j++) { sprites[(i *

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

拈花ヽ惹草 提交于 2019-11-27 05:22:44
问题 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 6 years ago . 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

How do I draw an image to a JPanel or JFrame?

老子叫甜甜 提交于 2019-11-27 05:02:54
How do I draw an Image to a JPanel or JFrame, I have already read oracle's tutorial on this but I can't seem to get it right. I need the image " BeachRoad.png " to be displayed on a specific set of coordinates. Here is what I have so far. public class Level1 extends JFrame implements ActionListener { static JLayeredPane EverythingButPlayer; static Level1 l1; public Level1() { EverythingButPlayer = new JLayeredPane(); BufferedImage img = null; try { img = ImageIO.read(new File("BeachRoad.png")); } catch (IOException e) { } Graphics g = img.getGraphics(); g.drawImage(img,0, 0,

Java: Filling a BufferedImage with transparent pixels

老子叫甜甜 提交于 2019-11-27 04:24:25
I have an off-screen BufferedImage, constructed with the type BufferedImage.TYPE_INT_ARGB . It can contain anything, and I'm looking for a way to (fairly efficiently) completely overwrite the image with transparent pixels, resulting in an 'invisible' image. Using something like this: (bufimg.getGraphics()).setColor(new Color(10, 10, 100, 0)); (bufimg.getGraphics()).fillRect (0, 0, x, y); Has no effect. One possible method might be just to write over every pixel in the BufferedImage, but I'm not sure this is the best solution. How would you do it? [edit] The Graphics documentation advises

Bufferedimage resize

心不动则不痛 提交于 2019-11-27 04:11:21
I am trying to resized a bufferedimage. I am able to store it and show up on a jframe no problems but I can't seem to resize it. Any tips on how I can change this to make it work and show the image as a 200*200 file would be great private void profPic(){ String path = factory.getString("bottle"); BufferedImage img = ImageIO.read(new File(path)); } public static BufferedImage resize(BufferedImage img, int newW, int newH) { int w = img.getWidth(); int h = img.getHeight(); BufferedImage dimg = new BufferedImage(newW, newH, img.getType()); Graphics2D g = dimg.createGraphics(); g.setRenderingHint

Re-sizing an image without losing quality

扶醉桌前 提交于 2019-11-27 03:32:30
I made this code to resize images with two factors. It works, but the quality of image is very bad after it is resized! Can you help me? This is the code public class ImageTest { private static final int factor1 = 3; private static final int factor2 = 4; public static void main(String [] args){ JFileChooser cs = new JFileChooser(); cs.setFileSelectionMode(cs.DIRECTORIES_ONLY); int i = cs.showOpenDialog(null); if(i==cs.APPROVE_OPTION){ File f = cs.getSelectedFile(); File[] ff = f.listFiles(); for(int j=0;j<ff.length;j++){ String end = ff[j].getName().substring(ff[j].getName().indexOf(".")+1);

How can I import java.awt.image.BufferedImage in Android Studio

心已入冬 提交于 2019-11-27 03:24:40
问题 I need my android app to recognize BufferedImage and I am using Android Studio. I've seen that there is a way to import JRE library system in Eclipse but I am having trouble doing so in Android Studio. Any ideas? Thanks! 回答1: You can't. The AWT package is not supported in Android, you need to change your implementation to use the Android classes. See these similar questions: Porting AWT graphics code to Android How to add java AWT image package in Android Using AWT with Android 来源: https:/